find
find a value in a list
(list xs, function p) -> any
Tests each x
in xs
in order by passing them to predicate function p
.
If p
accepts a single argument, p(x)
is evaluated. If p
accepts two arguments, p(x, i)
is evaluated, where i
is the index of x
in xs
Returns the first x
for which p
returns a value that casts to boolean true.
Returns nil
if xs
is nil
or p
is nil
.
Returns nil
if p
does not return true for any x
of xs
.
Parameters
Name | Type | Description |
---|---|---|
xs |
list | The list to work with |
p |
function |
A predicate function of the form (any x, long i) -> boolean that returns true if item x at index i should be returned as found. |