@monstermann/fn
Version:
A utility library for TypeScript.
22 lines (20 loc) • 467 B
JavaScript
import { dfdlT } from "@monstermann/dfdl";
//#region src/array/atOr.ts
/**
* `atOr(array, offset, fallback)`
*
* Returns the value at the specified `offset`. Returns `fallback` if the `offset` was out of range, or the retrieved value was nullable.
*
* ```ts
* atOr([1, null], -1, 2); // 2
* ```
*
* ```ts
* pipe([1, null], atOr(-1, 2)); // 2
* ```
*/
const atOr = dfdlT((target, offset, or) => {
return target.at(offset) ?? or;
}, 3);
//#endregion
export { atOr };