UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

41 lines 963 B
//#region src/number/orElse.d.ts /** * `orElse(target, orElse)` * * Returns the numeric value of `target` if it's a finite number, otherwise calls the `orElse` function with the original value and returns its result. * * ```ts * orElse(42, () => 0); // 42 * orElse(NaN, () => 0); // 0 * orElse(Infinity, (val) => `Not finite: ${val}`); // "Not finite: Infinity" * orElse("hello", (val) => val.length); // 5 * ``` * * ```ts * pipe( * 42, * orElse(() => 0), * ); // 42 * * pipe( * NaN, * orElse(() => 0), * ); // 0 * * pipe( * Infinity, * orElse((val) => `Not finite: ${val}`), * ); // "Not finite: Infinity" * * pipe( * "hello", * orElse((val) => val.length), * ); // 5 * ``` */ declare const orElse: { <T, U>(orElse: (value: NoInfer<T>) => U): (target: T) => Extract<T, number> | U; <T, U>(target: T, orElse: (value: NoInfer<T>) => U): Extract<T, number> | U; }; //#endregion export { orElse };