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