kojima/types/option.d.ts
2025-10-22 01:49:12 -04:00

396 lines
9.1 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<any>;
/**
* @template T
* @param {(value: T) => Option<T>} fn
* @param {Option<T>} self
* @returns {Option<T>}
*/
static chain<T_1>(fn: (value: T_1) => Option<T_1>, self: Option<T_1>): Option<T_1>;
/**
* @template T
* @param {(value: T) => boolean} predicate
* @param {Option<T>} self
* @returns {Option<T>}
*/
static filter<T_1>(predicate: (value: T_1) => boolean, self: Option<T_1>): Option<T_1>;
/**
* @template T,V
* @param {(value: T) => V} fn
* @param {Option<T>} self
* @returns {Option<V>}
*/
static map<T_1, V>(fn: (value: T_1) => V, self: Option<T_1>): Option<V>;
/**
* @template T
* @param {Option<T>} other
* @param {Option<T>} self
* @returns {Option<T>}
*/
static alt<T_1>(other: Option<T_1>, self: Option<T_1>): Option<T_1>;
/**
* @template T
* @param {Option<T>} other
* @param {Option<T>} self
* @returns {Option<T>}
*/
static equals<T_1>(other: Option<T_1>, self: Option<T_1>): Option<T_1>;
/**
* @template T
* @param {Option<T>} other
* @param {Option<T>} self
* @returns {Option<T>}
*/
static lte<T_1>(other: Option<T_1>, self: Option<T_1>): Option<T_1>;
/**
* @returns {this is Some}
*/
isSome(): this is Some<any>;
/**
* @returns {this is _None}
*/
isNone(): this is _None<any>;
/**
* @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: Option<T>): Option<T>;
/**
* @param {() => Option<T>} _fn
* @returns {Option<T>}
*/
orElse(_fn: () => Option<T>): Option<T>;
/**
* @param {(value: T) => boolean} predicate
* @returns {Option<T>}
*/
filter(predicate: (value: T) => boolean): Option<T>;
/**
* @param {Option<T>} other
* @returns {boolean}
*/
equals(other: Option<T>): boolean;
/**
* @param {Option<T>} other
* @returns {boolean}
*/
lte(other: Option<T>): boolean;
/**
* @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
* @param {() => E} _err
* @returns {Result<T, E>}
*/
okOrElse<E>(_err: () => E): 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;
}
/**
* @template T
* @augments Option<T>
*/
export class Some<T> extends Option<T> {
/** @param {T} value */
constructor(value: T);
/**
* @returns {this is Some}
*/
isSome(): this is Some<any>;
/**
* @returns {this is _None}
*/
isNone(): this is _None<any>;
/**
* @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: Option<T>): Option<T>;
/**
* @param {() => Option<T>} _fn
* @returns {Option<T>}
*/
orElse(_fn: () => Option<T>): Option<T>;
/**
* @param {(value: T) => boolean} predicate
* @returns {Option<T>}
*/
filter(predicate: (value: T) => boolean): Option<T>;
/**
* @param {Option<T>} other
* @returns {boolean}
*/
equals(other: Option<T>): boolean;
/**
* @param {Option<T>} other
* @returns {boolean}
*/
lte(other: Option<T>): boolean;
/**
* @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
* @param {() => E} _err
* @returns {Result<T, E>}
*/
okOrElse<E>(_err: () => E): 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<any>;
/**
* @template T
* @augments Option<T>
*/
declare class _None<T> extends Option<T> {
/**
* @returns {this is Some<T>}
*/
isSome(): this is Some<T>;
/**
* @returns {this is _None<T>}
*/
isNone(): this is _None<T>;
/**
* @param {Option<T>} _other
* @returns {Option<T>}
*/
and(_other: Option<T>): Option<T>;
/**
* @template {Option<T>} R
* @param {(value: T) => R} _fn
* @returns {R}
*/
andThen<R extends Option<T>>(_fn: (value: T) => R): R;
/**
* @param {Option<T>} other
* @returns {Option<T>}
*/
or(other: Option<T>): Option<T>;
/**
* @param {() => Option<T>} fn
* @returns {Option<T>}
*/
orElse(fn: () => Option<T>): Option<T>;
/**
* @param {(value: T) => boolean} _predicate
* @returns {Option<T>}
*/
filter(_predicate: (value: T) => boolean): Option<T>;
/**
* @param {Option<T>} other
* @returns {boolean}
*/
equals(other: Option<T>): boolean;
/**
* @param {Option<T>} _other
* @returns {boolean}
*/
lte(_other: Option<T>): boolean;
/**
* @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;
/**
* @template {Option<T>} R
* @returns {R}
*/
flatten<R extends Option<T>>(): R;
/**
* @template V
* @param {(value: T) => V} _fn
* @returns {Option<V>}
*/
map<V>(_fn: (value: T) => V): Option<V>;
/**
* @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 E
* @template {Result<T, E>} R
* @param {E} err
* @returns {R}
*/
okOr<E, R extends Result<T, E>>(err: E): R;
/**
* @template E
* @param {() => E} err
* @returns {Result<T, E>}
*/
okOrElse<E>(err: () => E): 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;
}
import { Result } from './result.js';
export { };
//# sourceMappingURL=option.d.ts.map