UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

33 lines (31 loc) 1.15 kB
import { OrElse } from "./internals/types.js"; //#region src/array/replaceOrElse.d.ts /** * `replaceOrElse(target, value, replacement, orElse)` * * Replaces the first occurrence of `value` in `target` with `replacement`. If `value` is not found, calls `orElse` with the original array. * * ```ts * replaceOrElse([1, 2, 3, 2], 2, 9, () => []); // [1, 9, 3, 2] * replaceOrElse([1, 2, 3], 4, 9, (arr) => arr); // [1, 2, 3] * ``` * * ```ts * pipe( * [1, 2, 3, 2], * replaceOrElse(2, 9, () => []), * ); // [1, 9, 3, 2] * pipe( * [1, 2, 3], * replaceOrElse(4, 9, (arr) => arr), * ); // [1, 2, 3] * ``` */ declare const replaceOrElse: { <T, U>(value: NoInfer<T>, replacement: NoInfer<T>, orElse: OrElse<T, U>): (target: T[]) => T[] | U; <T, U>(value: NoInfer<T>, replacement: NoInfer<T>, orElse: OrElse<T, U>): (target: readonly T[]) => readonly T[] | U; <T, U>(target: T[], value: NoInfer<T>, replacement: NoInfer<T>, orElse: OrElse<T, U>): T[] | U; <T, U>(target: readonly T[], value: NoInfer<T>, replacement: NoInfer<T>, orElse: OrElse<T, U>): readonly T[] | U; }; //#endregion export { replaceOrElse };