26.9 Other patterns of for loops

Predicate functions - return TRUE or FALSE

  • keep and discard - keep elements are TRUE and discard are FALSE.

  • some and every - determine if TRUE for any (some) or all (every)

  • detect and detect_index - detect finds first element where TRUE, and detect_index returns the position

  • head_while() and tail_while() - while TRUE 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.