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