UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

26 lines (24 loc) 641 B
import { OrElse } from "./internals/types.js"; //#region src/array/randomOrElse.d.ts /** * `randomOrElse(array, callback)` * * Returns a random element from `array`, or the result of calling `callback` with the array if the array is empty. * * ```ts * randomOrElse([1, 2, 3, 4], (arr) => arr.length); // 2 (random) * ``` * * ```ts * pipe( * [1, 2, 3, 4], * randomOrElse((arr) => arr.length), * ); // 2 (random) * ``` */ declare const randomOrElse: { <T, U>(orElse: OrElse<T, U>): (target: readonly T[]) => T | U; <T, U>(target: readonly T[], orElse: OrElse<T, U>): T | U; }; //#endregion export { randomOrElse };