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