on master help sign in
Implement unlines and unwords

--HG-- extra : convert_revision : a64baf5f128707a8a1f842f08dc69fd3f960a836

commit5d8a30f354b21287f4e00a644ef6ca80f5f2bd2a authorBryan O'Sullivan <bos@serpentine.com> dateWed 28 Jan 2009, 05:04 (18 years ago) parent1b5eb28
1 file changed+14−1
Data/Text.hs+14−1
Data/Text.hs+14−1
@@ -109,8 +109,10 @@ module Data.Text
109109 -- , breakSubstring
110110
111111 -- ** Breaking into lines and words
112− , words
113112 , lines
113+ , words
114+ , unlines
115+ , unwords
114116
115117 -- * Predicates
116118 -- , isPrefixOf
@@ -655,5 +657,16 @@ lines ps
655657 where search = elemIndex '\n'
656658{-# INLINE lines #-}
657659
660+-- | /O(n)/ Joins lines, after appending a terminating newline to
661+-- each.
662+unlines :: [Text] -> Text
663+unlines = concat . L.map (`snoc` '\n')
664+{-# INLINE unlines #-}
665+
666+-- | /O(n)/ Joins words using single space characters.
667+unwords :: [Text] -> Text
668+unwords = intercalate (singleton ' ')
669+{-# INLINE unwords #-}
670+
658671errorEmptyList :: String -> a
659672errorEmptyList fun = error ("Data.Text." ++ fun ++ ": empty list")