1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2025-01-07 18:34:00 +09:00
cherrypick/src/prelude/maybe.ts

21 lines
291 B
TypeScript
Raw Normal View History

export interface Maybe<T> {
isJust(): this is Just<T>;
}
export type Just<T> = Maybe<T> & {
get(): T
};
export function just<T>(value: T): Just<T> {
return {
isJust: () => true,
get: () => value
};
}
export function nothing<T>(): Maybe<T> {
return {
isJust: () => false,
};
}