@monstermann/fn
Version:
A utility library for TypeScript.
20 lines • 606 B
TypeScript
//#region src/array/insertAtOr.d.ts
/**
* `insertAtOr(array, index, value, fallback)`
*
* Inserts `value` at the specified `index` in `array`, returning a new array with the inserted element, or `fallback` if the index is out of bounds.
*
* ```ts
* insertAtOr([1, 2, 3], 10, 99, []); // []
* ```
*
* ```ts
* pipe([1, 2, 3], insertAtOr(10, 99, [])); // []
* ```
*/
declare const insertAtOr: {
<T, U>(idx: number, value: NoInfer<T>, or: U): (target: readonly T[]) => T[] | U;
<T, U>(target: readonly T[], idx: number, value: NoInfer<T>, or: U): T[] | U;
};
//#endregion
export { insertAtOr };