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.

32 lines 1.1 kB
import { type UnwrapOk } from './types.mjs'; /** * Unwraps a `Result`, returning the success value or a default value if it is * `Result.Err`. * * @example * * ```ts * const okValue = Result.ok(10); * * const errValue = Result.err('fail'); * * assert.isTrue(Result.unwrapOkOr(okValue, 0) === 10); * * assert.isTrue(Result.unwrapOkOr(errValue, 0) === 0); * * const unwrapWithDefault = Result.unwrapOkOr(5); * * assert.isTrue(unwrapWithDefault(Result.ok(3)) === 3); * * assert.isTrue(unwrapWithDefault(Result.err('no data')) === 5); * ``` * * @template R The `UnknownResult` type to unwrap. * @template D The type of the default value. * @param result The `Result` to unwrap. * @param defaultValue The value to return if `result` is `Result.Err`. * @returns The success value if `Result.Ok`, otherwise `defaultValue`. */ export declare function unwrapOkOr<R extends UnknownResult, D>(result: R, defaultValue: D): D | UnwrapOk<R>; export declare function unwrapOkOr<S, D>(defaultValue: D): <E>(result: Result<S, E>) => D | S; //# sourceMappingURL=result-unwrap-ok-or.d.mts.map