mapAccumL

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"])
The mapAccumL function behaves like a combination of map and foldl; it applies a function to each element of a ByteString, passing an accumulating parameter from left to right, and returning a final value of this accumulator together with the new ByteString.
The mapAccumL function behaves like a combination of map and foldl; it applies a function to each element of a ByteString, passing an accumulating parameter from left to right, and returning a final value of this accumulator together with the new ByteString.
O(n) Like a combination of map and foldl'. Applies a function to each element of a Text, passing an accumulating parameter from left to right, and returns a final Text. Performs replacement on invalid scalar values.
O(n) Like a combination of map and foldl'. Applies a function to each element of a Text, passing an accumulating parameter from left to right, and returns a final Text. Properties
mapAccumL g z0 . stream = mapAccumL g z0
O(n) Like a combination of map and foldl'. Applies a function to each element of a Text, passing an accumulating parameter from left to right, and returns a final Text. Performs replacement on invalid scalar values.
The mapAccumL function behaves like a combination of map and foldl; it applies a function to each element of a ByteString, passing an accumulating parameter from left to right, and returning a final value of this accumulator together with the new list.
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.
O(n) Like a combination of map and foldl'. Applies a function to each element of a JSString, passing an accumulating parameter from left to right, and returns a final JSString. Performs replacement on invalid scalar values.
O(n) Like a combination of map and foldl'. Applies a function to each element of a Text, passing an accumulating parameter from left to right, and returns a final JSString.
Equivalent to mapAccumL from Data.List when applied to a String, but preserves all non-character data.
The mapAccumL function behaves like a combination of map and foldl; it applies a function to each element of a Vector, passing an accumulating parameter from left to right, and returning a final value of this accumulator together with the new list.
The mapAccumL function behaves like a combination of map and foldl; it applies a function to each element of a vector, passing an accumulating parameter from left to right, and returning a final value of this accumulator together with the new vector.
>>> mapAccumL (\acc x -> (acc + x,acc + 1)) 0 (1 :> 2 :> 3 :> 4 :> Nil)
(10,1 :> 2 :> 4 :> 7 :> Nil)
"mapAccumL f acc xs" corresponds to the following circuit layout:
The mapAccumL function behaves like a combination of map and foldl; it applies a function to each element of a list, passing an accumulating parameter from left to right, and returning a final value of this accumulator together with the new list. mapAccumL does not force accumulator if it is unused:
>>> take 1 (snd (mapAccumL (\_ x -> (undefined, x)) undefined ('a' : undefined)))
"a"
Fold an infinite list from the left and return a list of successive reductions, keeping accumulator in a state:
mapAccumL f acc0 (x1 :< x2 :< ...) =
let (acc1, y1) = f acc0 x1 in
let (acc2, y2) = f acc1 x2 in
...
y1 :< y2 :< ...
If you are looking how to traverse with a state, look no further.
Lifted version of mapAccumL. Prior to v0.2.3, required a Backprop constraint on t b.
mapAccumL, but taking explicit add and zero.
mapAccumL, but with Num constraints instead of Backprop constraints. Prior to v0.2.3, required a Num constraint on t b.
Threads an accumulating argument through the map in ascending order of keys. Satisfies the following property:
mapAccumL f s m ==
fmap fromMap (Traversable.mapAccumL f s (toMap m))