@monstermann/fn
Version:
A utility library for TypeScript.
27 lines (25 loc) • 733 B
TypeScript
import { NonNil } from "../internals/types.js";
import { OrElse } from "./internals/types.js";
//#region src/array/atOrElse.d.ts
/**
* `atOrElse(array, offset, fallback)`
*
* Returns the value at the specified `offset`. Calls `fallback` if the `offset` was out of range, or the retrieved value was nullable.
*
* ```ts
* atOrElse([1, null], -1, (array) => array.length); // 2
* ```
*
* ```ts
* pipe(
* [1, null],
* atOrElse(-1, (array) => array.length),
* ); // 2
* ```
*/
declare const atOrElse: {
<T, U>(offset: number, orElse: OrElse<T, U>): (target: readonly T[]) => NonNil<T> | U;
<T, U>(target: readonly T[], offset: number, orElse: OrElse<T, U>): NonNil<T> | U;
};
//#endregion
export { atOrElse };