find(p, s, @key default = false)
Return the first element in the sequence s
for which the predicate p
return
a truth value. If no such element, return default
.
The predicate should accept one argument and return a single value. It should not modify the sequence.
let s = [1, 2, 3, 4, 5]
find(is_even, s)
// 2
find(is_even, list_to_array(s))
// 2
s = [1, 3, 5]
find(is_even, s)
// false
find(is_even, s, default = 10)
// 10
s = [true, false, true]
find(is_false, s, default = 'nil)
// false
s = [true, true, true]
find(is_false, s, default = 'nil)
// nil
function cust_seq(xs)
^(msg)
| 'first -> ^(_) first(xs)
| 'rest -> ^(_) rest(xs)
s = cust_seq([1,2,3,4,5])
find(^(x) x == 4, s)
// 4
find(^(x) x == 10, s)
// false