on master help sign in
Implement intercalate
42196e1Bryan O'Sullivan
Data/Text.hs+8
@@ -50,6 +50,7 @@ module Data.Text
50
50
51 -- * Transformations
51 -- * Transformations
52 , map
52 , map
53+ , intercalate
53 , intersperse
54 , intersperse
54 , transpose
55 , transpose
55
56
@@ -306,6 +307,13 @@ map :: (Char -> Char) -> Text -> Text
306map f t = unstream (S.map f (stream t))
307map f t = unstream (S.map f (stream t))
307{-# INLINE [1] map #-}
308{-# INLINE [1] map #-}
308
309
310+-- | /O(n)/ The 'intercalate' function takes a 'Text' and a list of
311+-- 'Text's and concatenates the list after interspersing the first
312+-- argument between each element of the list.
313+intercalate :: Text -> [Text] -> Text
314+intercalate t ts = unstream (S.intercalate (stream t) (L.map stream ts))
315+{-# INLINE intercalate #-}
316+
309-- | /O(n)/ The 'intersperse' function takes a character and places it
317-- | /O(n)/ The 'intersperse' function takes a character and places it
310-- between the characters of a 'Text'. Subject to array fusion.
318-- between the characters of a 'Text'. Subject to array fusion.
311intersperse :: Char -> Text -> Text
319intersperse :: Char -> Text -> Text
Data/Text/Fusion.hs+5
@@ -39,6 +39,7 @@ module Data.Text.Fusion
39
39
40 -- * Transformations
40 -- * Transformations
41 , map
41 , map
42+ , intercalate
42 , intersperse
43 , intersperse
43
44
44 -- * Folds
45 -- * Folds
@@ -442,6 +443,10 @@ foldr1 f (Stream next s0 _len) = loop0_foldr1 s0
442 Yield x' s' -> f x (loop_foldr1 x' s')
443 Yield x' s' -> f x (loop_foldr1 x' s')
443{-# INLINE [0] foldr1 #-}
444{-# INLINE [0] foldr1 #-}
444
445
446+intercalate :: Stream Char -> [Stream Char] -> Stream Char
447+intercalate s = concat . (L.intersperse s)
448+{-# INLINE [0] intercalate #-}
449+
445-- ----------------------------------------------------------------------------
450-- ----------------------------------------------------------------------------
446-- ** Special folds
451-- ** Special folds
447
452