fold package:containers

Deprecated: Use Data.IntSet.foldr instead
Deprecated: Use Data.Set.foldr instead
Fold the keys and values in the map using the given monoid, such that
foldMapWithKey f = fold . mapWithKey f
This can be an asymptotically faster than foldrWithKey or foldlWithKey for some monoids.
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
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.
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)"
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.
Fold the values in the map using the given right-associative binary operator, such that foldr f z == foldr f z . elems. For example,
elems map = foldr (:) [] map
let f a len = len + (length a)
foldr f 0 (fromList [(5,"a"), (3,"bbb")]) == 4
A strict version of foldr. Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.
Fold the keys and values in the map using the given right-associative binary operator, such that foldrWithKey f z == foldr (uncurry f) z . toAscList. For example,
keys map = foldrWithKey (\k x ks -> k:ks) [] map
let f k a result = result ++ "(" ++ (show k) ++ ":" ++ a ++ ")"
foldrWithKey f "Map: " (fromList [(5,"a"), (3,"b")]) == "Map: (5:a)(3:b)"
A strict version of foldrWithKey. Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.
Map the elements in the set to a monoid and combine with (<>).
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
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.
Fold the elements in the set using the given right-associative binary operator, such that foldr f z == foldr f z . toAscList. For example,
toAscList set = foldr (:) [] set
A strict version of foldr. Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.
Fold the keys and values in the map using the given monoid, such that
foldMapWithKey f = fold . mapWithKey f
This can be an asymptotically faster than foldrWithKey or foldlWithKey for some monoids.
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
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.
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)"
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.
Fold the values in the map using the given right-associative binary operator, such that foldr f z == foldr f z . elems. For example,
elems map = foldr (:) [] map
let f a len = len + (length a)
foldr f 0 (fromList [(5,"a"), (3,"bbb")]) == 4
A strict version of foldr. Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.
Fold the keys and values in the map using the given right-associative binary operator, such that foldrWithKey f z == foldr (uncurry f) z . toAscList. For example,
keys map = foldrWithKey (\k x ks -> k:ks) [] map
let f k a result = result ++ "(" ++ (show k) ++ ":" ++ a ++ ")"
foldrWithKey f "Map: " (fromList [(5,"a"), (3,"b")]) == "Map: (5:a)(3:b)"