mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-15 14:37:36 -07:00
21 lines
291 B
TypeScript
21 lines
291 B
TypeScript
|
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,
|
||
|
};
|
||
|
}
|