UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

26 lines (24 loc) 798 B
import { OrElse } from "./internals/types.js"; //#region src/array/insertAtOrElse.d.ts /** * `insertAtOrElse(array, index, value, callback)` * * Inserts `value` at the specified `index` in `array`, returning a new array with the inserted element, or the result of calling `callback` with the array if the index is out of bounds. * * ```ts * insertAtOrElse([1, 2, 3], 10, 99, (arr) => arr.length); // 3 * ``` * * ```ts * pipe( * [1, 2, 3], * insertAtOrElse(10, 99, (arr) => arr.length), * ); // 3 * ``` */ declare const insertAtOrElse: { <T, U>(idx: number, value: NoInfer<T>, orElse: OrElse<T, U>): (target: readonly T[]) => T[] | U; <T, U>(target: readonly T[], idx: number, value: NoInfer<T>, orElse: OrElse<T, U>): T[] | U; }; //#endregion export { insertAtOrElse };