jecs-nightly/src/util/result.luau
2025-03-02 05:07:57 +01:00

24 lines
404 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>)