O(n) foldr, applied to a binary operator, a starting
value (typically the right-identity of the operator), and a
Text, reduces the
Text using the binary operator, from
right to left.
If the binary operator is strict in its second argument, use
foldr' instead.
foldr is lazy like
foldr for lists: evaluation actually
traverses the
Text from left to right, only as far as it needs
to.
For example,
head can be defined with
O(1) complexity
using
foldr:
head :: Text -> Char
head = foldr const (error "head empty")
Searches from left to right with short-circuiting behavior can also be
defined using
foldr (
e.g.,
any,
all,
find,
elem).