@monstermann/fn
Version:
A utility library for TypeScript.
28 lines (26 loc) • 869 B
TypeScript
import { ArrayMap } from "./internals/types.js";
//#region src/array/mapAtOr.d.ts
/**
* `mapAtOr(array, index, mapper, fallback)`
*
* Applies the `mapper` function to the element at the specified `index` in `array`, returning a new array with the mapped element, or `fallback` if the index is out of bounds.
*
* ```ts
* mapAtOr([1, 2, 3], 10, (x) => x * 10, []); // []
* ```
*
* ```ts
* pipe(
* [1, 2, 3],
* mapAtOr(10, (x) => x * 10, []),
* ); // []
* ```
*/
declare const mapAtOr: {
<T, U>(idx: number, map: ArrayMap<T>, or: U): (target: T[]) => T[] | U;
<T, U>(idx: number, map: ArrayMap<T>, or: U): (target: readonly T[]) => readonly T[] | U;
<T, U>(target: T[], idx: number, map: ArrayMap<T>, or: U): T[] | U;
<T, U>(target: readonly T[], idx: number, map: ArrayMap<T>, or: U): readonly T[] | U;
};
//#endregion
export { mapAtOr };