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.

39 lines 1.49 kB
/** * Returns the `Optional` if it is `Some`, otherwise returns the alternative. * * Provides a way to chain Optional operations with fallback values. This is * particularly useful for implementing default behavior or cascading lookups. * Supports both direct usage and curried form for functional composition. * * @example * * ```ts * const preferred = Optional.some('primary'); * * const fallback = Optional.some('secondary'); * * const noneValue = Optional.none as Optional<string>; * * assert.deepStrictEqual(Optional.orElse(preferred, fallback), preferred); * * assert.deepStrictEqual(Optional.orElse(noneValue, fallback), fallback); * * const orElseFallback = Optional.orElse(Optional.some('default')); * * assert.deepStrictEqual(orElseFallback(Optional.none), Optional.some('default')); * * assert.deepStrictEqual( * orElseFallback(Optional.some('value')), * Optional.some('value'), * ); * ``` * * @template O The input `UnknownOptional` type. * @param optional The `Optional` to check. * @param alternative The alternative `Optional` to return if the first is * `None`. * @returns The first `Optional` if `Some`, otherwise the alternative. */ export declare function orElse<O extends UnknownOptional, const O2 extends UnknownOptional>(optional: O, alternative: O2): O | O2; export declare function orElse<S, S2>(alternative: Optional<S2>): (optional: Optional<S>) => Optional<S> | Optional<S2>; //# sourceMappingURL=optional-or-else.d.mts.map