UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

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