UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

28 lines (26 loc) 1.08 kB
import { ArrayPredicate } from "./internals/types.js"; //#region src/array/findReplaceLastOr.d.ts /** * `findReplaceLastOr(array, predicate, replacement, fallback)` * * Finds the last element in `array` that satisfies the provided `predicate` function and replaces it with `replacement`, returning a new array with the replaced element, or `fallback` if no element is found. * * ```ts * findReplaceLastOr([1, 2, 3, 4], (x) => x > 10, 99, []); // [] * ``` * * ```ts * pipe( * [1, 2, 3, 4], * findReplaceLastOr((x) => x > 10, 99, []), * ); // [] * ``` */ declare const findReplaceLastOr: { <T, U>(predicate: ArrayPredicate<T>, replacement: NoInfer<T>, or: U): (target: T[]) => T[] | U; <T, U>(predicate: ArrayPredicate<T>, replacement: NoInfer<T>, or: U): (target: readonly T[]) => readonly T[] | U; <T, U>(target: T[], predicate: ArrayPredicate<T>, replacement: NoInfer<T>, or: U): T[] | U; <T, U>(target: readonly T[], predicate: ArrayPredicate<T>, replacement: NoInfer<T>, or: U): readonly T[] | U; }; //#endregion export { findReplaceLastOr };