FoundKey/src/prelude/maybe.ts
Aya Morisawa e9955e01d6
Introduce option type (#4150)
* Introduce option type

* Improve test naming
2019-02-06 13:42:35 +09:00

20 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,
};
}