foldl package:rio

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.
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
O(n). Fold the values in the map using the given left-associative binary operator, such that foldl f z == foldl f z . elems. For example,
elems = reverse . foldl (flip (:)) []
let f len a = len + (length a)
foldl f 0 (fromList [(5,"a"), (3,"bbb")]) == 4
O(n). Fold the elements in the set using the given left-associative binary operator, such that foldl f z == foldl f z . toAscList. For example,
toDescList set = foldl (flip (:)) [] set
O(n) foldl, applied to a binary operator, a starting value (typically the left-identity of the operator), and a Text, reduces the Text using the binary operator, from left to right. Subject to fusion.
O(n) Left fold
O(n) Left fold
O(n) Left fold
O(n) Left fold
foldl' is like foldl, but strict in the accumulator.
Consume the chunks of a lazy ByteString with a strict, tail-recursive, accumulating left 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.
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.
Fold over a Deque, starting at the beginning. 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 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.
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
A variant of foldl that has no base case, and thus may only be applied to non-empty structures.
foldl1 f = foldl1 f . toList
A strict version of foldl1
O(n). A strict version of foldl. Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.
O(n). Fold the keys and values in the map using the given left-associative binary operator, such that foldlWithKey f z == foldl (\z' (kx, x) -> f z' kx x) z . toAscList. For example,
keys = reverse . foldlWithKey (\ks k x -> k:ks) []
let f result k a = result ++ "(" ++ (show k) ++ ":" ++ a ++ ")"
foldlWithKey f "Map: " (fromList [(5,"a"), (3,"b")]) == "Map: (3:b)(5:a)"
O(n). A strict version of foldlWithKey. Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.