Creates a function that returns the first element from an iterable or undefined if empty, with optional sorting.
The type of elements in the iterable
Optional
Optional comparator function to use for sorting the iterable before getting the first element
A function that takes an iterable and returns its first element or undefined if empty
// Get first element without sortingconst first = G.maybeFirst();first([3, 1, 2]); // 3first([]); // undefined// Get smallest element with sortingconst ascending = (a, b) => a - b;const smallest = G.maybeFirst(ascending);smallest([3, 1, 2]); // 1smallest([]); // undefined Copy
// Get first element without sortingconst first = G.maybeFirst();first([3, 1, 2]); // 3first([]); // undefined// Get smallest element with sortingconst ascending = (a, b) => a - b;const smallest = G.maybeFirst(ascending);smallest([3, 1, 2]); // 1smallest([]); // undefined
first - For a throwing variant when no elements exist
Creates a function that returns the first element from an iterable or undefined if empty, with optional sorting.