mapAccum -package:reflex

The function mapAccum threads an accumulating argument through the map in ascending order of keys.
let f a b = (a ++ b, b ++ "X")
mapAccum f "Everything: " (fromList [(5,"a"), (3,"b")]) == ("Everything: ba", fromList [(3, "bX"), (5, "aX")])
The function mapAccum threads an accumulating argument through the map in ascending order of keys.
let f a b = (a ++ b, b ++ "X")
mapAccum f "Everything: " (fromList [(5,"a"), (3,"b")]) == ("Everything: ba", fromList [(3, "bX"), (5, "aX")])
Map both the return value and output of a computation using the given function.
Analog of mapAccumL for lists. Note that in contrast to mapAccumL, the function argument takes the accumulator as its second argument, not its first argument, and the accumulated value is strict. Subject to fusion Since 1.1.1
The function mapAccum threads an accumulating argument through the map in ascending order of keys.
let f a b = (a ++ b, b ++ "X")
mapAccum f "Everything: " (fromList [(5,"a"), (3,"b")]) == ("Everything: ba", fromList [(3, "bX"), (5, "aX")])
O(n). The function mapAccum threads an accumulating argument through the map in ascending order of keys.
let f a b = (a ++ b, b ++ "X")
mapAccum f "Everything: " (fromList [(5,"a"), (3,"b")]) == ("Everything: ba", fromList [(3, "bX"), (5, "aX")])
Efficient combination of accumE and accumB.
The function mapAccum threads an accumulating argument through the map in unspecified order of keys.
O(n). The function mapAccum threads an accumulating argument through the map in ascending order of keys.
let f a b = (a ++ b, b ++ "X")
mapAccum f "Everything: " (fromList ((5,"a") :| [(3,"b")])) == ("Everything: ba", fromList ((3, "bX") :| [(5, "aX")]))
O(n). The function mapAccum threads an accumulating argument through the map in ascending order of keys.
let f a b = (a ++ b, b ++ "X")
mapAccum f "Everything: " (fromList ((5,"a") :| [(3,"b")])) == ("Everything: ba", fromList ((3, "bX") :| [(5, "aX")]))
Efficient combination of accumE and accumB.
O(n). The function mapAccum threads an accumulating argument through the map in ascending order of keys.
O(n). The function mapAccum threads an accumulating argument through the map in ascending order of keys.
let f a b = (a ++ b, b ++ "X")
mapAccum f "Everything: " (fromList [(5,"a"), (3,"b")]) == ("Everything: ba", fromList [(3, "bX"), (5, "aX")])
O(n). The function mapAccum threads an accumulating argument through the map in ascending order of keys.
Map a pure "stateful" function over each incoming item. Give a function to update the state and return an output and an initial state.
The mapAccumL function behaves like a combination of fmap and foldl; it applies a function to each element of a structure, passing an accumulating parameter from left to right, and returning a final value of this accumulator together with the new structure.

Examples

Basic usage:
>>> mapAccumL (\a b -> (a + b, a)) 0 [1..10]
(55,[0,1,3,6,10,15,21,28,36,45])
>>> mapAccumL (\a b -> (a <> show b, a)) "0" [1..5]
("012345",["0","01","012","0123","01234"])