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.28 kB
import { type Unwrap } from './types.mjs'; /** * Unwraps an `Optional`, returning the contained value or a default value if * it's `None`. * * Supports both direct usage and curried form for functional composition. * This is often preferred over `unwrap()` when you have a sensible fallback * value. * * @example * * ```ts * const withValue = Optional.some(5); * * const withoutValue = Optional.none as Optional<number>; * * assert.isTrue(Optional.unwrapOr(withValue, 0) === 5); * * assert.isTrue(Optional.unwrapOr(withoutValue, 0) === 0); * * const unwrapWithDefault = Optional.unwrapOr(10); * * assert.isTrue(unwrapWithDefault(Optional.some(3)) === 3); * * assert.isTrue(unwrapWithDefault(Optional.none) === 10); * ``` * * @template O The `UnknownOptional` type to unwrap. * @template D The type of the default value. * @param optional The `Optional` to unwrap. * @param defaultValue The value to return if `optional` is `None`. * @returns The contained value if `Some`, otherwise `defaultValue`. */ export declare function unwrapOr<O extends UnknownOptional, D>(optional: O, defaultValue: D): D | Unwrap<O>; export declare function unwrapOr<S, D>(defaultValue: D): (optional: Optional<S>) => D | S; //# sourceMappingURL=optional-unwrap-or.d.mts.map