@monstermann/fn
Version:
A utility library for TypeScript.
26 lines • 899 B
TypeScript
//#region src/array/setAtOr.d.ts
/**
* `setAtOr(target, idx, value, or)`
*
* Sets the value at the specified `idx` in `target` to `value`. If the index is out of bounds, returns `or`.
*
* ```ts
* setAtOr([1, 2, 3], 1, 9, []); // [1, 9, 3]
* setAtOr([1, 2, 3], -1, 9, []); // [1, 2, 9]
* setAtOr([1, 2, 3], 5, 9, []); // []
* ```
*
* ```ts
* pipe([1, 2, 3], setAtOr(1, 9, [])); // [1, 9, 3]
* pipe([1, 2, 3], setAtOr(-1, 9, [])); // [1, 2, 9]
* pipe([1, 2, 3], setAtOr(5, 9, [])); // []
* ```
*/
declare const setAtOr: {
<T, U>(idx: number, value: NoInfer<T>, or: U): (target: T[]) => T[] | U;
<T, U>(idx: number, value: NoInfer<T>, or: U): (target: readonly T[]) => readonly T[] | U;
<T, U>(target: T[], idx: number, value: NoInfer<T>, or: U): T[] | U;
<T, U>(target: readonly T[], idx: number, value: NoInfer<T>, or: U): readonly T[] | U;
};
//#endregion
export { setAtOr };