2023-07-27 05:31:52 +00:00
|
|
|
/*
|
2024-02-13 15:59:27 +00:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 05:31:52 +00:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
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,
|
2021-12-09 14:58:30 +00:00
|
|
|
get: () => value,
|
2019-02-06 04:42:35 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
}
|