26.9 Other patterns of for loops
Predicate functions - return TRUE
or FALSE
keep
anddiscard
- keep elements areTRUE
and discard areFALSE
.some
andevery
- determine ifTRUE
for any (some) or all (every)detect
anddetect_index
- detect finds first element whereTRUE
, and detect_index returns the positionhead_while()
andtail_while()
- whileTRUE
take elements from start (head_while) or end (tail_while)
Reduce and accumulate
reduce()
takes a “binary” function, applies it repeatedly to a list until there is only a single element left.accumulate()
keeps all the interim results.