UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

29 lines (27 loc) 914 B
import { NonNil } from "../internals/types.js"; import { ArrayGuard, ArrayPredicate } from "./internals/types.js"; //#region src/array/findOr.d.ts /** * `findOr(array, predicate, fallback)` * * Returns the first element in `array` that satisfies the provided `predicate` function, or `fallback` if no element is found. * * ```ts * findOr([1, 2, 3, 4], (x) => x > 10, 0); // 0 * ``` * * ```ts * pipe( * [1, 2, 3, 4], * findOr((x) => x > 10, 0), * ); // 0 * ``` */ declare const findOr: { <T, U extends T, V>(predicate: ArrayGuard<T, U>, or: V): (target: readonly T[]) => NonNil<U> | V; <T, V>(predicate: ArrayPredicate<T>, or: V): (target: readonly T[]) => NonNil<T> | V; <T, U extends T, V>(target: readonly T[], predicate: ArrayGuard<T, U>, or: V): NonNil<U> | V; <T, V>(target: readonly T[], predicate: ArrayPredicate<T>, or: V): NonNil<T> | V; }; //#endregion export { findOr };