UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

28 lines (26 loc) 856 B
import { ArrayMap } from "./internals/types.js"; //#region src/array/mapAtOrThrow.d.ts /** * `mapAtOrThrow(array, index, mapper)` * * Applies the `mapper` function to the element at the specified `index` in `array`, returning a new array with the mapped element, or throws an error if the index is out of bounds. * * ```ts * mapAtOrThrow([1, 2, 3, 4], 1, (x) => x * 10); // [1, 20, 3, 4] * ``` * * ```ts * pipe( * [1, 2, 3, 4], * mapAtOrThrow(1, (x) => x * 10), * ); // [1, 20, 3, 4] * ``` */ declare const mapAtOrThrow: { <T>(idx: number, map: ArrayMap<T>): (target: T[]) => T[]; <T>(idx: number, map: ArrayMap<T>): (target: readonly T[]) => readonly T[]; <T>(target: T[], idx: number, map: ArrayMap<T>): T[]; <T>(target: readonly T[], idx: number, map: ArrayMap<T>): readonly T[]; }; //#endregion export { mapAtOrThrow };