mapAccumL -bytestring

mapAccumL :: (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])
base Data.List
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 :: Traversable t => (a -> b -> (a, c)) -> a -> t b -> (a, t c)
base Data.Traversable
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.
mapAccumL :: (a -> Char -> (a, Char)) -> a -> Text -> (a, Text)
text Data.Text, text Data.Text.Lazy
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.