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