Commits

Bryan O'Sullivan  committed 92bbe47

Static argument transformation for mapAccum[LR]

  • Participants
  • Parent commits ee2a7f8

Comments (0)

Files changed (2)

File Data/Text.hs

 -- function to each element of a 'Text', passing an accumulating
 -- parameter from left to right, and returns a final 'Text'.
 mapAccumL :: (a -> Char -> (a,Char)) -> a -> Text -> (a, Text)
-mapAccumL f s t = case uncons t of
-                    Nothing -> (s, empty)
-                    Just (x, xs) -> (s'', cons y ys)
-                        where (s', y ) = f s x
-                              (s'',ys) = mapAccumL f s' xs
+mapAccumL f = go
+  where go s t = case uncons t of
+                   Nothing -> (s, empty)
+                   Just (x, xs) -> (s'', cons y ys)
+                       where (s', y ) = f s x
+                             (s'',ys) = go s' xs
+{-# INLINE mapAccumL #-}
 
 -- | The 'mapAccumR' function behaves like a combination of 'map' and
 -- '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'.
 mapAccumR :: (a -> Char -> (a,Char)) -> a -> Text -> (a, Text)
-mapAccumR f s t = case uncons t of
-                    Nothing -> (s, empty)
-                    Just (x, xs) ->  (s'', cons y ys)
-                        where (s'',y ) = f s' x
-                              (s', ys) = mapAccumR f s xs
+mapAccumR f = go
+  where go s t = case uncons t of
+                   Nothing -> (s, empty)
+                   Just (x, xs) ->  (s'', cons y ys)
+                       where (s'',y ) = f s' x
+                             (s', ys) = go s xs
+{-# INLINE mapAccumR #-}
 
 -- -----------------------------------------------------------------------------
 -- ** Generating and unfolding 'Text's

File Data/Text/Lazy.hs

 -- function to each element of a 'Text', passing an accumulating
 -- parameter from left to right, and returns a final 'Text'.
 mapAccumL :: (a -> Char -> (a,Char)) -> a -> Text -> (a, Text)
-mapAccumL f s t = case uncons t of
-                    Nothing -> (s, empty)
-                    Just (x, xs) -> (s'', cons y ys)
-                        where (s', y ) = f s x
-                              (s'',ys) = mapAccumL f s' xs
+mapAccumL f = go
+  where go s t = case uncons t of
+                   Nothing -> (s, empty)
+                   Just (x, xs) -> (s'', cons y ys)
+                       where (s', y ) = f s x
+                             (s'',ys) = go s' xs
+{-# INLINE mapAccumL #-}
 
 -- | The 'mapAccumR' function behaves like a combination of 'map' and
 -- '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'.
 mapAccumR :: (a -> Char -> (a,Char)) -> a -> Text -> (a, Text)
-mapAccumR f s t = case uncons t of
-                    Nothing -> (s, empty)
-                    Just (x, xs) ->  (s'', cons y ys)
-                        where (s'',y ) = f s' x
-                              (s', ys) = mapAccumR f s xs
+mapAccumR f = go
+  where go s t = case uncons t of
+                   Nothing -> (s, empty)
+                   Just (x, xs) ->  (s'', cons y ys)
+                       where (s'',y ) = f s' x
+                             (s', ys) = go s xs
+{-# INLINE mapAccumR #-}
 
 -- | /O(n*m)/ 'replicate' @n@ @t@ is a 'Text' consisting of the input
 -- @t@ repeated @n@ times.