mapAccumR -bytestring +text

mapAccumR :: (a -> Char -> (a, Char)) -> a -> Text -> (a, Text)
text Data.Text, text Data.Text.Lazy
The mapAccumR function behaves like a combination of map and a strict foldr; it applies a function to each element of a Text, passing an accumulating parameter from right to left, and returning a final value of this accumulator together with the new Text. Performs replacement on invalid scalar values.