findFirst
lib.findFirst
Docs pulled from | This Revision | 10 minutes ago
Find the first element in the list matching the specified
predicate or return default
if no such element exists.
Inputs
pred
-
Predicate
default
-
Default value to return
list
-
Input list
Type
findFirst :: (a -> bool) -> a -> [a] -> a
Examples
lib.lists.findFirst
usage example
findFirst (x: x > 3) 7 [ 1 6 4 ]
=> 6
findFirst (x: x > 9) 7 [ 1 6 4 ]
=> 7
Noogle detected
Implementation
The following is the current implementation of this function.
findFirst =
pred: default: list:
let
index = findFirstIndex pred null list;
in
if index == null then default else elemAt list index;