@@ -83,8 +83,8 @@ module Data.Text.Lazy
8383 -- , scanr1
8484
8585 -- ** Accumulating maps
86− -- , mapAccumL
87− -- , mapAccumR
86+ , mapAccumL
87+ , mapAccumR
8888
8989 -- ** Generation and unfolding
9090 -- , replicate
@@ -447,6 +447,27 @@ scanl1 f t0 = case uncons t0 of
447447 Just (t,ts) -> scanl f t ts
448448{-# INLINE scanl1 #-}
449449
450+-- | /O(n)/ Like a combination of 'map' and 'foldl'. Applies a
451+-- function to each element of a 'Text', passing an accumulating
452+-- parameter from left to right, and returns a final 'Text'.
453+mapAccumL :: (a -> Char -> (a,Char)) -> a -> Text -> (a, Text)
454+mapAccumL f s t = case uncons t of
455+ Nothing -> (s, empty)
456+ Just (x, xs) -> (s'', cons y ys)
457+ where (s', y ) = f s x
458+ (s'',ys) = mapAccumL f s' xs
459+
460+-- | The 'mapAccumR' function behaves like a combination of 'map' and
461+-- 'foldr'; it applies a function to each element of a 'Text', passing
462+-- an accumulating parameter from right to left, and returning a final
463+-- value of this accumulator together with the new 'Text'.
464+mapAccumR :: (a -> Char -> (a,Char)) -> a -> Text -> (a, Text)
465+mapAccumR f s t = case uncons t of
466+ Nothing -> (s, empty)
467+ Just (x, xs) -> (s'', cons y ys)
468+ where (s'',y ) = f s' x
469+ (s', ys) = mapAccumR f s xs
470+
450471-- | /O(n)/ 'splitAt' @n t@ returns a pair whose first element is a
451472-- prefix of @t@ of length @n@, and whose second is the remainder of
452473-- the string. It is equivalent to @('take' n t, 'drop' n t)@.