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