@monstermann/fn
Version:
A utility library for TypeScript.
27 lines (25 loc) • 680 B
TypeScript
import { NonNil } from "../internals/types.js";
import { OrElse } from "./internals/types.js";
//#region src/array/firstOrElse.d.ts
/**
* `firstOrElse(array, callback)`
*
* Returns the first element of `array`, or the result of calling `callback` with the array if the array is empty.
*
* ```ts
* firstOrElse([1, 2, 3, 4], (arr) => arr.length); // 1
* ```
*
* ```ts
* pipe(
* [1, 2, 3, 4],
* firstOrElse((arr) => arr.length),
* ); // 1
* ```
*/
declare const firstOrElse: {
<T, U>(orElse: OrElse<T, U>): (target: readonly T[]) => NonNil<T> | U;
<T, U>(target: readonly T[], orElse: OrElse<T, U>): NonNil<T> | U;
};
//#endregion
export { firstOrElse };