UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

29 lines (27 loc) 898 B
import { NonNil } from "../internals/types.js"; import { ArrayGuard, ArrayPredicate } from "./internals/types.js"; //#region src/array/findLastOrThrow.d.ts /** * `findLastOrThrow(array, predicate)` * * Returns the last element in `array` that satisfies the provided `predicate` function, or throws an error if no element is found. * * ```ts * findLastOrThrow([1, 2, 3, 4], (x) => x > 2); // 4 * ``` * * ```ts * pipe( * [1, 2, 3, 4], * findLastOrThrow((x) => x > 2), * ); // 4 * ``` */ declare const findLastOrThrow: { <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 { findLastOrThrow };