find package:base

The find function takes a predicate and a structure and returns the leftmost element of the structure matching the predicate, or Nothing if there is no such element.

Examples

Basic usage:
>>> find (> 42) [0, 5..]
Just 45
>>> find (> 12) [1..7]
Nothing
The findIndex function takes a predicate and a list and returns the index of the first element in the list satisfying the predicate, or Nothing if there is no such element. For the result to be Nothing, the list must be finite.

Examples

>>> findIndex isSpace "Hello World!"
Just 5
>>> findIndex odd [0, 2, 4, 6]
Nothing
>>> findIndex even [1..]
Just 1
>>> findIndex odd [0, 2 ..]
* hangs forever *
The findIndices function extends findIndex, by returning the indices of all elements satisfying the predicate, in ascending order.

Examples

>>> findIndices (`elem` "aeiou") "Hello World!"
[1,4,7]
>>> findIndices (\l -> length l > 3) ["a", "bcde", "fgh", "ijklmnop"]
[1,3]
The bifind function takes a predicate and a structure and returns the leftmost element of the structure matching the predicate, or Nothing if there is no such element.

Examples

Basic usage:
>>> bifind even (27, 53)
Nothing
>>> bifind even (27, 52)
Just 52
>>> bifind even (26, 52)
Just 26
Empty structures always yield Nothing:
>>> bifind even (BiList [] [])
Nothing