on master help sign in
Implement unlines and unwords
5d8a30fBryan O'Sullivan
Data/Text.hs+14−1
@@ -109,8 +109,10 @@ module Data.Text
109 -- , breakSubstring
109 -- , breakSubstring
110
110
111 -- ** Breaking into lines and words
111 -- ** Breaking into lines and words
112− , words
113 , lines
112 , lines
113+ , words
114+ , unlines
115+ , unwords
114
116
115 -- * Predicates
117 -- * Predicates
116 -- , isPrefixOf
118 -- , isPrefixOf
@@ -655,5 +657,16 @@ lines ps
655 where search = elemIndex '\n'
657 where search = elemIndex '\n'
656{-# INLINE lines #-}
658{-# INLINE lines #-}
657
659
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+
658errorEmptyList :: String -> a
671errorEmptyList :: String -> a
659errorEmptyList fun = error ("Data.Text." ++ fun ++ ": empty list")
672errorEmptyList fun = error ("Data.Text." ++ fun ++ ": empty list")