Add show()

This commit is contained in:
Richard 2023-09-18 16:19:53 -07:00
parent c4a0180a2f
commit d1da0b4ea5
2 changed files with 20 additions and 0 deletions

18
src/show.luau Normal file
View 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)?)