@monstermann/fn
Version:
A utility library for TypeScript.
24 lines • 930 B
TypeScript
//#region src/array/insertAllAtOrThrow.d.ts
/**
* `insertAllAtOrThrow(target, idx, values)`
*
* Inserts all `values` at the specified `idx` in `target`. If the index is out of bounds, throws an error. Supports iterables.
*
* ```ts
* insertAllAtOrThrow([1, 2, 3], 1, [8, 9]); // [1, 8, 9, 2, 3]
* insertAllAtOrThrow([1, 2, 3], 5, [8, 9]); // throws FnError
* ```
*
* ```ts
* pipe([1, 2, 3], insertAllAtOrThrow(1, [8, 9])); // [1, 8, 9, 2, 3]
* pipe([1, 2, 3], insertAllAtOrThrow(5, [8, 9])); // throws FnError
* ```
*/
declare const insertAllAtOrThrow: {
<T>(idx: number, values: Iterable<NoInfer<T>>): (target: T[]) => T[];
<T>(idx: number, values: Iterable<NoInfer<T>>): (target: readonly T[]) => readonly T[];
<T>(target: T[], idx: number, values: Iterable<NoInfer<T>>): T[];
<T>(target: readonly T[], idx: number, values: Iterable<NoInfer<T>>): readonly T[];
};
//#endregion
export { insertAllAtOrThrow };