Bryan O'Sullivan avatar Bryan O'Sullivan committed c3799e9

Fix up lazy concat and concatMap.

Comments (0)

Files changed (1)


 foldr1 f t = S.foldr1 f (stream t)
 {-# INLINE foldr1 #-}
--- | /O(n)/ Concatenate a list of 'Text's. Subject to array fusion.
+-- | /O(n)/ Concatenate a list of 'Text's.
 concat :: [Text] -> Text
-concat ts = unstream (S.concat ( stream ts))
+concat = to
+  where
+    go Empty        css = to css
+    go (Chunk c cs) css = Chunk c (go cs css)
+    to []               = Empty
+    to (cs:css)         = go cs css
 {-# INLINE concat #-}
 -- | /O(n)/ Map a function over a 'Text' that results in a 'Text', and
--- concatenate the results.  This function is subject to array fusion.
--- Note: if in 'concatMap' @f@ @t@, @f@ is defined in terms of fusible
--- functions, it will also be fusible.
+-- concatenate the results.
 concatMap :: (Char -> Text) -> Text -> Text
-concatMap f t = unstream (S.concatMap (stream . f) (stream t))
+concatMap f = concat . foldr ((:) . f) []
 {-# INLINE concatMap #-}
 -- | /O(n)/ 'any' @p@ @t@ determines whether any character in the
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.