286 lines
No EOL
6.6 KiB
TypeScript
286 lines
No EOL
6.6 KiB
TypeScript
/**
|
|
* @template T
|
|
*/
|
|
export class Option<T> {
|
|
/**
|
|
* @template T
|
|
* @param {T} value
|
|
* @returns {Some<T>}
|
|
*/
|
|
static some<T_1>(value: T_1): Some<T_1>;
|
|
/** @returns {None} */
|
|
static none(): _None;
|
|
/**
|
|
* @param {(value: T) => Option<T>} fn
|
|
* @param {Option<T>} self
|
|
* @returns {Option<T>}
|
|
*/
|
|
static chain(fn: (value: T) => Option<T>, self: Option<T>): Option<T>;
|
|
/**
|
|
* @param {(value: T) => bool} fn
|
|
* @param {Option<T>} self
|
|
* @returns {Option<T>}
|
|
*/
|
|
static filter(predicate: any, self: Option<T>): Option<T>;
|
|
/**
|
|
* @template V
|
|
* @param {(value: T) => V} fn
|
|
* @param {Option<T>} self
|
|
* @returns {Option<V>}
|
|
*/
|
|
static map<V>(fn: (value: T) => V, self: Option<T>): Option<V>;
|
|
/**
|
|
* @param {Option<T>} other
|
|
* @param {Option<T>} self
|
|
* @returns {Option<T>}
|
|
*/
|
|
static alt(other: Option<T>, self: Option<T>): Option<T>;
|
|
/**
|
|
* @param {Option<T>} other
|
|
* @param {Option<T>} self
|
|
* @returns {Option<T>}
|
|
*/
|
|
static equals(other: Option<T>, self: Option<T>): Option<T>;
|
|
/**
|
|
* @param {Option<T>} other
|
|
* @param {Option<T>} self
|
|
* @returns {Option<T>}
|
|
*/
|
|
static lte(other: Option<T>, self: Option<T>): Option<T>;
|
|
/**
|
|
* @returns {this is Some<T>}
|
|
*/
|
|
isSome(): this is Some<T>;
|
|
/**
|
|
* @returns {this is None<T>}
|
|
*/
|
|
isNone(): this is _None;
|
|
}
|
|
/** @template T */
|
|
export class Some<T> extends Option<any> {
|
|
/** @param {T} value */
|
|
constructor(value: T);
|
|
/**
|
|
* @param {(value: T) => Option<T>} fn
|
|
* @returns {Option<T>}
|
|
*/
|
|
andThen(fn: (value: T) => Option<T>): Option<T>;
|
|
/**
|
|
* @param {Option<T>} other
|
|
* @returns {Option<T>}
|
|
*/
|
|
and(other: Option<T>): Option<T>;
|
|
/**
|
|
* @param {Option<T>} other
|
|
* @returns {Option<T>}
|
|
*/
|
|
or(_other: any): Option<T>;
|
|
/**
|
|
* @param {() => Option<T>} other
|
|
* @returns {Option<T>}
|
|
*/
|
|
orElse(_fn: any): Option<T>;
|
|
/**
|
|
* @template T
|
|
* @param {(value: T) => bool} predicate
|
|
* @returns {Option<T>}
|
|
*/
|
|
filter<T_1>(predicate: (value: T_1) => bool): Option<T_1>;
|
|
/**
|
|
* @param {Option<T>} other
|
|
* @returns {bool}
|
|
*/
|
|
equals(other: Option<T>): bool;
|
|
/**
|
|
* @param {Option<T>} other
|
|
* @returns {bool}
|
|
*/
|
|
lte(other: Option<T>): bool;
|
|
/**
|
|
* @template [V=T]
|
|
* @param {(acc: V, value: T) => V} reducer
|
|
* @param {V} init
|
|
* @returns {V}
|
|
*/
|
|
reduce<V = T>(reducer: (acc: V, value: T) => V, init: V): V;
|
|
/**
|
|
* @returns {Option<T>}
|
|
*/
|
|
flatten(): Option<T>;
|
|
/**
|
|
* @template V
|
|
* @param {(value: T) => V} fn
|
|
* @returns {Option<V>}
|
|
*/
|
|
map<V>(fn: (value: T) => V): Option<V>;
|
|
/**
|
|
* @template V
|
|
* @param {V} _default
|
|
* @param {(value: T) => V} fn
|
|
* @returns {V}
|
|
*/
|
|
mapOr<V>(_default: V, fn: (value: T) => V): V;
|
|
/**
|
|
* @template V
|
|
* @param {() => V} _defaultFn
|
|
* @param {(value: T) => V} fn
|
|
* @returns {V}
|
|
*/
|
|
mapOrElse<V>(_defaultFn: () => V, fn: (value: T) => V): V;
|
|
/**
|
|
* @template E
|
|
* @param {E} _err
|
|
* @returns {Result<T, E>}
|
|
*/
|
|
okOr<E>(_err: E): Result<T, E>;
|
|
/**
|
|
* @template E
|
|
* @template {() => E} F
|
|
* @param {F} _err
|
|
* @returns {Result<T, E>}
|
|
*/
|
|
okOrElse<E, F extends () => E>(_err: F): Result<T, E>;
|
|
/**
|
|
* @param {(value: T) => void} fn
|
|
* @returns {this}
|
|
*/
|
|
inspect(fn: (value: T) => void): this;
|
|
/**
|
|
* @returns {T}
|
|
* @throws {UnwrapError}
|
|
*/
|
|
unwrap(): T;
|
|
/**
|
|
* @param {T} _value
|
|
* @returns {T}
|
|
*/
|
|
unwrapOr(_value: T): T;
|
|
/**
|
|
* @param {() => T} _fn
|
|
* @returns {T}
|
|
*/
|
|
unwrapOrElse(_fn: () => T): T;
|
|
#private;
|
|
}
|
|
export const None: _None;
|
|
declare class _None extends Option<any> {
|
|
constructor();
|
|
/**
|
|
* @template T
|
|
* @param {Option<T>} _other
|
|
* @returns {Option<T>}
|
|
*/
|
|
and<T>(_other: Option<T>): Option<T>;
|
|
/**
|
|
* @template T
|
|
* @template {Option<T>} R
|
|
* @param {(value: T) => R} fn
|
|
* @returns {R}
|
|
*/
|
|
andThen<T, R extends Option<T>>(_fn: any): R;
|
|
/**
|
|
* @template T
|
|
* @param {Option<T>} other
|
|
* @returns {Option<T>}
|
|
*/
|
|
or<T>(other: Option<T>): Option<T>;
|
|
/**
|
|
* @template T
|
|
* @param {() => Option<T>} other
|
|
* @returns {Option<T>}
|
|
*/
|
|
orElse<T>(fn: any): Option<T>;
|
|
/**
|
|
* @template T
|
|
* @param {(value: T) => bool} _predicate
|
|
* @returns {Option<T>}
|
|
*/
|
|
filter<T>(_predicate: (value: T) => bool): Option<T>;
|
|
/**
|
|
* @template T
|
|
* @param {Option<T>} other
|
|
* @returns {bool}
|
|
*/
|
|
equals<T>(other: Option<T>): bool;
|
|
/**
|
|
* @template T
|
|
* @param {Option<T>} _other
|
|
* @returns {bool}
|
|
*/
|
|
lte<T>(_other: Option<T>): bool;
|
|
/**
|
|
* @template T, [V=T]
|
|
* @param {(acc: V, value: T) => V} _reducer
|
|
* @param {V} init
|
|
* @returns {V}
|
|
*/
|
|
reduce<T, V = T>(_reducer: (acc: V, value: T) => V, init: V): V;
|
|
/**
|
|
* @template T
|
|
* @template {Option<T>} R
|
|
* @returns {R}
|
|
*/
|
|
flatten<T, R extends Option<T>>(): R;
|
|
/**
|
|
* @template V
|
|
* @template {Option<T>} R
|
|
* @param {(value: T) => V} fn
|
|
* @returns {R}
|
|
*/
|
|
map<V, R extends Option<T>>(_fn: any): R;
|
|
/**
|
|
* @template V
|
|
* @param {V} defaultValue
|
|
* @param {(value: T) => V} _fn
|
|
* @returns {V}
|
|
*/
|
|
mapOr<V>(defaultValue: V, _fn: (value: T) => V): V;
|
|
/**
|
|
* @template V
|
|
* @param {() => V} defaultFn
|
|
* @param {(value: T) => V} _fn
|
|
* @returns {V}
|
|
*/
|
|
mapOrElse<V>(defaultFn: () => V, _fn: (value: T) => V): V;
|
|
/**
|
|
* @template T, E
|
|
* @template {Result<T, E>} R
|
|
* @param {E} err
|
|
* @returns {R}
|
|
*/
|
|
okOr<T, E, R extends Result<T, E>>(err: E): R;
|
|
/**
|
|
* @template T, E
|
|
* @template {Result<T, E>} R
|
|
* @template {() => E} F
|
|
* @param {F} err
|
|
* @returns {R}
|
|
*/
|
|
okOrElse<T, E, R extends Result<T, E>, F extends () => E>(err: F): R;
|
|
/**
|
|
* @template T
|
|
* @param {(value: T) => void} _fn
|
|
* @returns {this}
|
|
*/
|
|
inspect<T>(_fn: (value: T) => void): this;
|
|
/**
|
|
* @template T
|
|
* @returns {T}
|
|
* @throws {UnwrapError}
|
|
*/
|
|
unwrap<T>(): T;
|
|
/**
|
|
* @param {T} value
|
|
* @returns {T}
|
|
*/
|
|
unwrapOr(value: T): T;
|
|
/**
|
|
* @template T
|
|
* @param {() => T} fn
|
|
* @returns {T}
|
|
*/
|
|
unwrapOrElse<T>(fn: () => T): T;
|
|
}
|
|
import { Result } from './result.js';
|
|
export {};
|
|
//# sourceMappingURL=option.d.ts.map
|