Bryan O'Sullivan avatar Bryan O'Sullivan committed 6a0a9df

Implement intercalate

Comments (0)

Files changed (2)

 
     -- * Transformations
     , map
+    , intercalate
     , intersperse
     , transpose
 
 map f t = unstream (S.map f (stream t))
 {-# INLINE [1] map #-}
 
+-- | /O(n)/ The 'intercalate' function takes a 'Text' and a list of
+-- 'Text's and concatenates the list after interspersing the first
+-- argument between each element of the list.
+intercalate :: Text -> [Text] -> Text
+intercalate t ts = unstream (S.intercalate (stream t) (L.map stream ts))
+{-# INLINE intercalate #-}
+
 -- | /O(n)/ The 'intersperse' function takes a character and places it
 -- between the characters of a 'Text'.  Subject to array fusion.
 intersperse     :: Char -> Text -> Text

Data/Text/Fusion.hs

 
     -- * Transformations
     , map
+    , intercalate
     , intersperse
 
     -- * Folds
       Yield x' s' -> f x (loop_foldr1 x' s')
 {-# INLINE [0] foldr1 #-}
 
+intercalate :: Stream Char -> [Stream Char] -> Stream Char
+intercalate s = concat . (L.intersperse s)
+{-# INLINE [0] intercalate #-}
+
 -- ----------------------------------------------------------------------------
 -- ** Special folds
 
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 ProjectModifiedEvent.java.
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.