@monstermann/fn
Version:
A utility library for TypeScript.
28 lines (26 loc) • 1.06 kB
TypeScript
import { ArrayPredicate } from "./internals/types.js";
//#region src/array/findReplaceLastOrThrow.d.ts
/**
* `findReplaceLastOrThrow(array, predicate, replacement)`
*
* 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 throws an error if no element is found.
*
* ```ts
* findReplaceLastOrThrow([1, 2, 3, 4], (x) => x > 2, 99); // [1, 2, 3, 99]
* ```
*
* ```ts
* pipe(
* [1, 2, 3, 4],
* findReplaceLastOrThrow((x) => x > 2, 99),
* ); // [1, 2, 3, 99]
* ```
*/
declare const findReplaceLastOrThrow: {
<T>(predicate: ArrayPredicate<T>, replacement: NoInfer<T>): (target: T[]) => T[];
<T>(predicate: ArrayPredicate<T>, replacement: NoInfer<T>): (target: readonly T[]) => readonly T[];
<T>(target: T[], predicate: ArrayPredicate<T>, replacement: NoInfer<T>): T[];
<T>(target: readonly T[], predicate: ArrayPredicate<T>, replacement: NoInfer<T>): readonly T[];
};
//#endregion
export { findReplaceLastOrThrow };