@@ -692,29 +692,30 @@ scanr1 :: (Char -> Char -> Char) -> Text -> Text
692692scanr1 f t | null t = empty
693693 | otherwise = scanr f (last t) (init t)
694694
695−-- | /O(n)/ Like a combination of 'map' and 'foldl'. Applies a
695+-- | /O(n)/ Like a combination of 'map' and 'foldl''. Applies a
696696-- function to each element of a 'Text', passing an accumulating
697697-- parameter from left to right, and returns a final 'Text'.
698698mapAccumL :: (a -> Char -> (a,Char)) -> a -> Text -> (a, Text)
699699mapAccumL f = go
700− where go s t = case uncons t of
701− Nothing -> (s, empty)
702− Just (x, xs) -> (s'', cons y ys)
703− where (s', y ) = f s x
704− (s'',ys) = go s' xs
700+ where
701+ go z (Chunk c cs) = (z'', Chunk c' cs')
702+ where (z', c') = T.mapAccumL f z c
703+ (z'', cs') = go z' cs
704+ go z Empty = (z, Empty)
705705{-# INLINE mapAccumL #-}
706706
707707-- | The 'mapAccumR' function behaves like a combination of 'map' and
708−-- 'foldr'; it applies a function to each element of a 'Text', passing
709−-- an accumulating parameter from right to left, and returning a final
710−-- value of this accumulator together with the new 'Text'.
708+-- a strict 'foldr'; it applies a function to each element of a
709+-- 'Text', passing an accumulating parameter from right to left, and
710+-- returning a final value of this accumulator together with the new
711+-- 'Text'.
711712mapAccumR :: (a -> Char -> (a,Char)) -> a -> Text -> (a, Text)
712713mapAccumR f = go
713− where go s t = case uncons t of
714− Nothing -> (s, empty)
715− Just (x, xs) -> (s'', cons y ys)
716− where (s'',y ) = f s' x
717− (s', ys) = go s xs
714+ where
715+ go z (Chunk c cs) = (z'', Chunk c' cs')
716+ where (z'', c') = T.mapAccumR f z' c
717+ (z', cs') = go z cs
718+ go z Empty = (z, Empty)
718719{-# INLINE mapAccumR #-}
719720
720721-- | /O(n*m)/ 'replicate' @n@ @t@ is a 'Text' consisting of the input