Creates a function that finds the first element in an iterable that satisfies a predicate. Returns undefined if no element is found.
The type of elements in the iterable
Function that tests each element; receives element and index
A function that takes an iterable and returns the first matching element or undefined
// Find first even numberconst findEven = G.maybeFind(x => x % 2 === 0);findEven([1, 3, 5, 6, 7]); // 6findEven([1, 3, 5, 7]); // undefined// Find using indexconst findSecondItem = G.maybeFind((_, i) => i === 1);findSecondItem(['a', 'b', 'c']); // 'b' Copy
// Find first even numberconst findEven = G.maybeFind(x => x % 2 === 0);findEven([1, 3, 5, 6, 7]); // 6findEven([1, 3, 5, 7]); // undefined// Find using indexconst findSecondItem = G.maybeFind((_, i) => i === 1);findSecondItem(['a', 'b', 'c']); // 'b'
find - For a throwing variant when no element is found
Creates a function that finds the first element in an iterable that satisfies a predicate. Returns undefined if no element is found.