UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

26 lines 892 B
//#region src/array/setAtOrThrow.d.ts /** * `setAtOrThrow(target, idx, value)` * * Sets the value at the specified `idx` in `target` to `value`. If the index is out of bounds, throws an error. * * ```ts * setAtOrThrow([1, 2, 3], 1, 9); // [1, 9, 3] * setAtOrThrow([1, 2, 3], -1, 9); // [1, 2, 9] * setAtOrThrow([1, 2, 3], 5, 9); // throws FnError * ``` * * ```ts * pipe([1, 2, 3], setAtOrThrow(1, 9)); // [1, 9, 3] * pipe([1, 2, 3], setAtOrThrow(-1, 9)); // [1, 2, 9] * pipe([1, 2, 3], setAtOrThrow(5, 9)); // throws FnError * ``` */ declare const setAtOrThrow: { <T>(idx: number, value: NoInfer<T>): (target: T[]) => T[]; <T>(idx: number, value: NoInfer<T>): (target: readonly T[]) => readonly T[]; <T>(target: T[], idx: number, value: NoInfer<T>): T[]; <T>(target: readonly T[], idx: number, value: NoInfer<T>): readonly T[]; }; //#endregion export { setAtOrThrow };