2019-04-14 03:18:17 -05:00
|
|
|
export interface IMaybe<T> {
|
|
|
|
isJust(): this is IJust<T>;
|
2019-02-05 22:42:35 -06:00
|
|
|
}
|
|
|
|
|
2019-04-14 03:18:17 -05:00
|
|
|
export interface IJust<T> extends IMaybe<T> {
|
|
|
|
get(): T;
|
|
|
|
}
|
2019-02-05 22:42:35 -06:00
|
|
|
|
2019-04-14 03:18:17 -05:00
|
|
|
export function just<T>(value: T): IJust<T> {
|
2019-02-05 22:42:35 -06:00
|
|
|
return {
|
|
|
|
isJust: () => true,
|
|
|
|
get: () => value
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-04-14 03:18:17 -05:00
|
|
|
export function nothing<T>(): IMaybe<T> {
|
2019-02-05 22:42:35 -06:00
|
|
|
return {
|
|
|
|
isJust: () => false,
|
|
|
|
};
|
|
|
|
}
|