firstOrElse
ts
function Array.firstOrElse<T, U>(
target: readonly T[],
orElse: (target: readonly NoInfer<T>[]) => U,
): Exclude<T, null | undefined> | UReturns the first element of array, or the result of calling callback with the array if the array is empty.
Example
ts
import { Array } from "@monstermann/array";
Array.firstOrElse([1, 2, 3, 4], (arr) => arr.length); // 1ts
import { Array } from "@monstermann/array";
pipe(
[1, 2, 3, 4],
Array.firstOrElse((arr) => arr.length),
); // 1