/** * A type used to express computations that can fail. * @typeparam T - Type of results. * @typeparam E - Type of errors. */ export declare type Result = Ok | Err; /** * The computation is successful. * @typeparam T - Type of results. */ export interface Ok { /** * If this is an Ok, this is true. */ readonly success: true; /** * The resulting value, which only exists on an Ok. */ readonly value: T; readonly error?: undefined; } /** * The computation failed. * @typeparam E - Type of errors. */ export interface Err { /** * If this an Err, this is false. */ readonly success: false; readonly value?: undefined; /** * The resulting error, which only exists on an Err. */ readonly error: E; } /** * Creates an Ok. * @typeparam T - Type of results. * @param x - Value to use. * @returns A Result. */ export declare function ok(x: T): Ok; /** * Creates an Err. * @typeparam E - Type of errors. * @param x - Value to use. * @returns A Result. */ export declare function err(x: E): Err; /** * Creates an Err with null value. * @returns A Result. */ export declare function err_(): Err; /** * Creates a Result from a value that could be null or undefined. * * ```ts * console.log(maybeResult(1, 'bad')); * >>> { success: true, value: 1 } * * console.log(maybeResult(null, 'bad')); * >>> { success: false, error: 'bad' } * * console.log(maybeResult(undefined, 'bad')); * >>> { success: false, error: 'bad' } * ``` * @param x - A nullable value. * @param e - The error to use. * @returns A Result. */ export declare function maybeResult(x: T | null | undefined, e: E): Result; /** * Gets the first Ok from many Results. * @param x - The first Result. * @param xs - The remaining Results; this encoding is to ensure there is at least one Result. * @return The first Ok, or all the Errs if there were no Ok. */ export declare function orResultAll(x: Result, ...xs: Result[]): Result; /** * Gets the first Ok from many Results. * @param x - The first Result. * @param xs - The remaining Results; this encoding is to ensure there is at least one Result. * @return The first Ok, or the first Err if there were no Ok. */ export declare function orResultFirst(x: Result, ...xs: Result[]): Result; /** * Gets the first Ok from many Results. * @param x - The first Result. * @param xs - The remaining Results; this encoding is to ensure there is at least one Result. * @return The first Ok, or the last Err if there were no Ok. */ export declare function orResultLast(x: Result, ...xs: Result[]): Result;