Check config on load (#4170)
Co-authored-by: syuilo <syuilotan@yahoo.co.jp>
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
export interface Maybe<T> {
|
||||
isJust(): this is Just<T>;
|
||||
map<S>(f: (x: T) => S): Maybe<S>;
|
||||
getOrElse(x: T): T;
|
||||
}
|
||||
|
||||
export type Just<T> = Maybe<T> & {
|
||||
@ -9,6 +11,8 @@ export type Just<T> = Maybe<T> & {
|
||||
export function just<T>(value: T): Just<T> {
|
||||
return {
|
||||
isJust: () => true,
|
||||
getOrElse: (_: T) => value,
|
||||
map: <S>(f: (x: T) => S) => just(f(value)),
|
||||
get: () => value
|
||||
};
|
||||
}
|
||||
@ -16,5 +20,11 @@ export function just<T>(value: T): Just<T> {
|
||||
export function nothing<T>(): Maybe<T> {
|
||||
return {
|
||||
isJust: () => false,
|
||||
getOrElse: (value: T) => value,
|
||||
map: <S>(_: (x: T) => S) => nothing<S>()
|
||||
};
|
||||
}
|
||||
|
||||
export function fromNullable<T>(value: T): Maybe<T> {
|
||||
return value == null ? nothing() : just(value);
|
||||
}
|
||||
|
Reference in New Issue
Block a user