254 lines
No EOL
5.8 KiB
TypeScript
254 lines
No EOL
5.8 KiB
TypeScript
/**
|
|
* @template T, E
|
|
*/
|
|
export class Result<T, E> {
|
|
/**
|
|
* @template T
|
|
* @param {T} value
|
|
*/
|
|
static ok<T_1>(value: T_1): Ok<T_1, any>;
|
|
/**
|
|
* @template E
|
|
* @param {E} error
|
|
*/
|
|
static err<E_1>(error: E_1): Err<any, E_1>;
|
|
static chain(fn: any, self: any): any;
|
|
static map(fn: any, self: any): any;
|
|
static alt(other: any, self: any): any;
|
|
static equals(other: any, self: any): any;
|
|
static lte(other: any, self: any): any;
|
|
/**
|
|
* @returns {this is Ok<T, E>}
|
|
*/
|
|
isOk(): this is Ok<T, E>;
|
|
/**
|
|
* @returns {this is Err<T, E>}
|
|
*/
|
|
isErr(): this is Err<T, E>;
|
|
}
|
|
/** @template T, E */
|
|
export class Ok<T, E> extends Result<any, any> {
|
|
/** @param {T} value */
|
|
constructor(value: T);
|
|
/**
|
|
* @returns {this is Ok<T, E>}
|
|
*/
|
|
isOk(): this is Ok<T, E>;
|
|
/**
|
|
* @returns {this is Err<T, E>}
|
|
*/
|
|
isErr(): this is Err<T, E>;
|
|
/**
|
|
* @template {Result<T, E>} R
|
|
* @param {(value: T) => R} fn
|
|
* @returns {R}
|
|
*/
|
|
andThen<R extends Result<T, E>>(fn: (value: T) => R): R;
|
|
/**
|
|
* @template V
|
|
* @template {Result<V, E>} R
|
|
* @param {(value: T) => V} fn
|
|
* @returns {R}
|
|
*/
|
|
map<V, R extends Result<V, E>>(fn: (value: T) => V): R;
|
|
/**
|
|
* @template V
|
|
* @param {V} _defaultValue
|
|
* @param {(value: T) => V} fn
|
|
* @returns {V}
|
|
*/
|
|
mapOr<V>(_defaultValue: V, fn: (value: T) => V): V;
|
|
/**
|
|
* @param {Result<T, E>} other
|
|
* @returns {Result<T, E>}
|
|
*/
|
|
and(other: Result<T, E>): Result<T, E>;
|
|
/**
|
|
* @param {Result<T, E>} _other
|
|
* @returns {Result<T, E>}
|
|
*/
|
|
or(_other: Result<T, E>): Result<T, E>;
|
|
/**
|
|
* @template F
|
|
* @param {(error: E) => Result<T, F>} _fn
|
|
* @returns {Result<T, F>}
|
|
*/
|
|
orElse<F>(_fn: (error: E) => Result<T, F>): Result<T, F>;
|
|
/**
|
|
* @param {Result<T, E>} other
|
|
* @returns {boolean}
|
|
*/
|
|
equals(other: Result<T, E>): boolean;
|
|
/**
|
|
* @param {Result<T, E>} other
|
|
* @returns {boolean}
|
|
*/
|
|
lte(other: Result<T, E>): 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 {Result<T, E>} R
|
|
* @returns {R}
|
|
*/
|
|
flatten<R extends Result<T, E>>(): R;
|
|
/**
|
|
* @returns {Option<T>}
|
|
*/
|
|
ok(): Option<T>;
|
|
/**
|
|
* @returns {Option<T>}
|
|
*/
|
|
err(): Option<T>;
|
|
/**
|
|
* @param {(value: T) => void} fn
|
|
* @returns {this}
|
|
*/
|
|
inspect(fn: (value: T) => void): this;
|
|
/**
|
|
* @returns {T}
|
|
* @throws {UnwrapError}
|
|
*/
|
|
unwrap(): T;
|
|
/**
|
|
* @returns {E}
|
|
* @throws {UnwrapError}
|
|
*/
|
|
unwrapErr(): E;
|
|
/**
|
|
* @param {T} _value
|
|
* @returns {T}
|
|
*/
|
|
unwrapOr(_value: T): T;
|
|
/**
|
|
* @param {() => T} _fn
|
|
* @returns {T}
|
|
*/
|
|
unwrapOrElse(_fn: () => T): T;
|
|
#private;
|
|
}
|
|
/** @template T, E */
|
|
export class Err<T, E> extends Result<any, any> {
|
|
/** @param {E} error */
|
|
constructor(error: E);
|
|
/**
|
|
* @returns {this is Ok<T, E>}
|
|
*/
|
|
isOk(): this is Ok<T, E>;
|
|
/**
|
|
* @returns {this is Err<T, E>}
|
|
*/
|
|
isErr(): this is Err<T, E>;
|
|
/**
|
|
* @template {Result<T, E>} R
|
|
* @param {(value: T) => R} _fn
|
|
* @returns {R}
|
|
*/
|
|
andThen<R extends Result<T, E>>(_fn: (value: T) => R): R;
|
|
/**
|
|
* @template V
|
|
* @template {Result<V, E>} R
|
|
* @param {(value: T) => V} _fn
|
|
* @returns {R}
|
|
*/
|
|
map<V, R extends Result<V, E>>(_fn: (value: T) => V): 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
|
|
* @param {Result<T, E>} _other
|
|
* @returns {Result<T, E>}
|
|
*/
|
|
and<T_1>(_other: Result<T_1, E>): Result<T_1, E>;
|
|
/**
|
|
* @template T
|
|
* @param {Result<T, E>} other
|
|
* @returns {Result<T, E>}
|
|
*/
|
|
or<T_1>(other: Result<T_1, E>): Result<T_1, E>;
|
|
/**
|
|
* @template T, F
|
|
* @param {(error: E) => Result<T, F>} fn
|
|
* @returns {Result<T, F>}
|
|
*/
|
|
orElse<T_1, F>(fn: (error: E) => Result<T_1, F>): Result<T_1, F>;
|
|
/**
|
|
* @template T
|
|
* @param {Result<T, E>} other
|
|
* @returns {boolean}
|
|
*/
|
|
equals<T_1>(other: Result<T_1, E>): boolean;
|
|
/**
|
|
* @template T
|
|
* @param {Result<T, E>} other
|
|
* @returns {boolean}
|
|
*/
|
|
lte<T_1>(other: Result<T_1, E>): 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 {Result<T, E>} R
|
|
* @returns {R}
|
|
*/
|
|
flatten<R extends Result<T, E>>(): R;
|
|
/**
|
|
* @returns {Option<T>}
|
|
*/
|
|
ok(): Option<T>;
|
|
/**
|
|
* @returns {Option<T>}
|
|
*/
|
|
err(): Option<T>;
|
|
/**
|
|
* @template T
|
|
* @param {(value: T) => void} _fn
|
|
* @returns {this}
|
|
*/
|
|
inspect<T_1>(_fn: (value: T_1) => void): this;
|
|
/**
|
|
* @template T
|
|
* @returns {T}
|
|
* @throws {UnwrapError}
|
|
*/
|
|
unwrap<T_1>(): T_1;
|
|
/**
|
|
* @returns {E}
|
|
* @throws {UnwrapError}
|
|
*/
|
|
unwrapErr(): E;
|
|
/**
|
|
* @param {T} value
|
|
* @returns {T}
|
|
*/
|
|
unwrapOr(value: T): T;
|
|
/**
|
|
* @template T
|
|
* @param {() => T} fn
|
|
* @returns {T}
|
|
*/
|
|
unwrapOrElse<T_1>(fn: () => T_1): T_1;
|
|
#private;
|
|
}
|
|
import { Option } from './option.js';
|
|
//# sourceMappingURL=result.d.ts.map
|