CSSharpTemplate/lune/pkg/result.luau
marked e517b193e5
All checks were successful
Build / Build (push) Successful in 39s
Initial push
2025-04-05 18:27:50 +02:00

24 lines
485 B
Text

--!strict
export type Identity<T> = {
ok: true,
val: T,
} | {
ok: false,
err: string,
}
local function construct<T>(ok: boolean, value: T & string): Identity<T>
if ok then
return {
ok = true,
val = value,
}
else
return {
ok = false,
err = value,
}
end
end
return (construct :: any) :: (<T>(ok: true, value: T) -> Identity<T>) & (<T>(ok: false, value: string) -> Identity<T>)