UNPKG

ts-data-forge

Version:

[![npm version](https://img.shields.io/npm/v/ts-data-forge.svg)](https://www.npmjs.com/package/ts-data-forge) [![npm downloads](https://img.shields.io/npm/dm/ts-data-forge.svg)](https://www.npmjs.com/package/ts-data-forge) [![License](https://img.shields.

36 lines 1.25 kB
import { type NarrowToOk } from './types.mjs'; /** * Returns the `Result` if it is `Ok`, otherwise returns the alternative. * * @example * * ```ts * const primary = Result.ok('primary'); * * const fallback = Result.ok('fallback'); * * const failure = Result.err('failure'); * * assert.deepStrictEqual(Result.orElse(primary, fallback), primary); * * assert.deepStrictEqual(Result.orElse(failure, fallback), fallback); * * const orElseFallback = Result.orElse(Result.ok('default')); * * assert.deepStrictEqual( * orElseFallback(Result.err('missing')), * Result.ok('default'), * ); * * assert.deepStrictEqual(orElseFallback(Result.ok('value')), Result.ok('value')); * ``` * * @template R The input `UnknownResult` type. * @param result The `Result` to check. * @param alternative The alternative `Result` to return if the first is * `Err`. * @returns The first `Result` if `Ok`, otherwise the alternative. */ export declare function orElse<R extends UnknownResult, R2 extends UnknownResult>(result: R, alternative: R2): NarrowToOk<R> | R2; export declare function orElse<S, E, S2, E2>(alternative: Result<S2, E2>): (result: Result<S, E>) => Result<S, E> | Result<S2, E2>; //# sourceMappingURL=result-or-else.d.mts.map