on master help sign in
Implement intercalate

--HG-- extra : convert_revision : 79041a8737d24e50778901a7cab1f4265c2bb73b

commit42196e1ade7a95f12d9a0fcf437dc1f39432ea0f authorBryan O'Sullivan <bos@serpentine.com> dateTue 27 Jan 2009, 06:53 (18 years ago) parenta74d560
2 files changed+13
Data/Text.hs+8 Data/Text/Fusion.hs+5
Data/Text.hs+8
@@ -50,6 +50,7 @@ module Data.Text
5050
5151 -- * Transformations
5252 , map
53+ , intercalate
5354 , intersperse
5455 , transpose
5556
@@ -306,6 +307,13 @@ map :: (Char -> Char) -> Text -> Text
306307map f t = unstream (S.map f (stream t))
307308{-# INLINE [1] map #-}
308309
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+
309317-- | /O(n)/ The 'intersperse' function takes a character and places it
310318-- between the characters of a 'Text'. Subject to array fusion.
311319intersperse :: Char -> Text -> Text
Data/Text/Fusion.hs+5
@@ -39,6 +39,7 @@ module Data.Text.Fusion
3939
4040 -- * Transformations
4141 , map
42+ , intercalate
4243 , intersperse
4344
4445 -- * Folds
@@ -442,6 +443,10 @@ foldr1 f (Stream next s0 _len) = loop0_foldr1 s0
442443 Yield x' s' -> f x (loop_foldr1 x' s')
443444{-# INLINE [0] foldr1 #-}
444445
446+intercalate :: Stream Char -> [Stream Char] -> Stream Char
447+intercalate s = concat . (L.intersperse s)
448+{-# INLINE [0] intercalate #-}
449+
445450-- ----------------------------------------------------------------------------
446451-- ** Special folds
447452