mirror of
https://github.com/centau/vide.git
synced 2026-08-20 23:01:37 +00:00
Add show()
This commit is contained in:
parent
c4a0180a2f
commit
d1da0b4ea5
2 changed files with 20 additions and 0 deletions
18
src/show.luau
Normal file
18
src/show.luau
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
if not game then script = require "test/relative-string" end
|
||||
|
||||
local switch = require(script.Parent.switch)
|
||||
|
||||
local function show<T>(source: () -> any, component: () -> T, fallback: (() -> T)?): () -> T?
|
||||
local function truthy()
|
||||
return not not source()
|
||||
end
|
||||
|
||||
return switch(truthy) {
|
||||
[true] = component,
|
||||
[false] = fallback,
|
||||
}
|
||||
end
|
||||
|
||||
return show ::
|
||||
(<T>(source: () -> any, component: () -> T) -> () -> T?) &
|
||||
(<T, U>(source: () -> any, component: () -> T, fallback: () -> U) -> () -> (T | U)?)
|
||||
Loading…
Add table
Add a link
Reference in a new issue