UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

24 lines 910 B
//#region src/array/replaceLastOrThrow.d.ts /** * `replaceLastOrThrow(target, value, replacement)` * * Replaces the last occurrence of `value` in `target` with `replacement`. If `value` is not found, throws an error. * * ```ts * replaceLastOrThrow([1, 2, 3, 2], 2, 9); // [1, 2, 3, 9] * replaceLastOrThrow([1, 2, 3], 4, 9); // throws FnError * ``` * * ```ts * pipe([1, 2, 3, 2], replaceLastOrThrow(2, 9)); // [1, 2, 3, 9] * pipe([1, 2, 3], replaceLastOrThrow(4, 9)); // throws FnError * ``` */ declare const replaceLastOrThrow: { <T>(value: NoInfer<T>, replacement: NoInfer<T>): (target: T[]) => T[]; <T>(value: NoInfer<T>, replacement: NoInfer<T>): (target: readonly T[]) => readonly T[]; <T>(target: T[], value: NoInfer<T>, replacement: NoInfer<T>): T[]; <T>(target: readonly T[], value: NoInfer<T>, replacement: NoInfer<T>): readonly T[]; }; //#endregion export { replaceLastOrThrow };