fold package:rio

Combine the elements of a structure using a monoid.
foldl, applied to a binary operator, a starting value (typically the left-identity of the operator), and a ByteString, reduces the ByteString using the binary operator, from left to right.
foldl' is like foldl, but strict in the accumulator.
foldr, applied to a binary operator, a starting value (typically the right-identity of the operator), and a ByteString, reduces the ByteString using the binary operator, from right to left.
foldr' is like foldr, but strict in the accumulator.
Consume the chunks of a lazy ByteString with a strict, tail-recursive, accumulating left fold.
Consume the chunks of a lazy ByteString with a natural right fold.
foldl1 is a variant of foldl that has no starting value argument, and thus must be applied to non-empty ByteStrings.
foldl1' is like foldl1, but strict in the accumulator.
foldr1 is a variant of foldr that has no starting value argument, and thus must be applied to non-empty ByteStrings
foldl1 is a variant of foldl that has no starting value argument, and thus must be applied to non-empty ByteStrings. An exception will be thrown in the case of an empty ByteString.
foldl1' is like foldl1, but strict in the accumulator. An exception will be thrown in the case of an empty ByteString.
foldr1 is a variant of foldr that has no starting value argument, and thus must be applied to non-empty ByteStrings An exception will be thrown in the case of an empty ByteString.
foldr1' is a variant of foldr1, but is strict in the accumulator.
Fold over a Deque, starting at the beginning. Does not modify the Deque.
Fold over a Deque, starting at the end. Does not modify the Deque.
Reduce this map by applying a binary operator to all elements, using the given starting value (typically the left-identity of the operator). Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.
Reduce this map by applying a binary operator to all elements, using the given starting value (typically the left-identity of the operator). Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.
Reduce this map by applying a binary operator to all elements, using the given starting value (typically the right-identity of the operator).
Reduce this map by applying a binary operator to all elements, using the given starting value (typically the right-identity of the operator).
Reduce this set by applying a binary operator to all elements, using the given starting value (typically the left-identity of the operator). Each application of the operator is evaluated before before using the result in the next application. This function is strict in the starting value.
Reduce this set by applying a binary operator to all elements, using the given starting value (typically the right-identity of the operator).
Left-associative fold of a structure. In the case of lists, foldl, when applied to a binary operator, a starting value (typically the left-identity of the operator), and a list, reduces the list using the binary operator, from left to right:
foldl f z [x1, x2, ..., xn] == (...((z `f` x1) `f` x2) `f`...) `f` xn
Note that to produce the outermost application of the operator the entire input list must be traversed. This means that foldl' will diverge if given an infinite list. Also note that if you want an efficient left-fold, you probably want to use foldl' instead of foldl. The reason for this is that latter does not force the "inner" results (e.g. z `f` x1 in the above example) before applying them to the operator (e.g. to (`f` x2)). This results in a thunk chain <math> elements long, which then must be evaluated from the outside-in. For a general Foldable structure this should be semantically identical to,
foldl f z = foldl f z . toList
Left-associative fold of a structure but with strict application of the operator. This ensures that each step of the fold is forced to weak head normal form before being applied, avoiding the collection of thunks that would otherwise occur. This is often what you want to strictly reduce a finite list to a single, monolithic result (e.g. length). For a general Foldable structure this should be semantically identical to,
foldl' f z = foldl' f z . toList
Right-associative fold of a structure. In the case of lists, foldr, when applied to a binary operator, a starting value (typically the right-identity of the operator), and a list, reduces the list using the binary operator, from right to left:
foldr f z [x1, x2, ..., xn] == x1 `f` (x2 `f` ... (xn `f` z)...)
Note that, since the head of the resulting expression is produced by an application of the operator to the first element of the list, foldr can produce a terminating expression from an infinite list. For a general Foldable structure this should be semantically identical to,
foldr f z = foldr f z . toList