@@ -81,7 +81,7 @@ module Data.Text
8181
8282 -- ** Accumulating maps
8383 , mapAccumL
84− -- , mapAccumR
84+ , mapAccumR
8585
8686 -- ** Generation and unfolding
8787 , replicate
@@ -538,6 +538,17 @@ mapAccumL f s t = case uncons t of
538538 where (s', y ) = f s x
539539 (s'',ys) = mapAccumL f s' xs
540540
541+-- | The 'mapAccumR' function behaves like a combination of 'map' and
542+-- 'foldr'; it applies a function to each element of a 'Text', passing
543+-- an accumulating parameter from right to left, and returning a final
544+-- value of this accumulator together with the new 'Text'.
545+mapAccumR :: (a -> Char -> (a,Char)) -> a -> Text -> (a, Text)
546+mapAccumR f s t = case uncons t of
547+ Nothing -> (s, empty)
548+ Just (x, xs) -> (s'', cons y ys)
549+ where (s'',y ) = f s' x
550+ (s', ys) = mapAccumR f s xs
551+
541552-- -----------------------------------------------------------------------------
542553-- ** Generating and unfolding 'Text's
543554