Commits

Bryan O'Sullivan  committed 69faab1

Implement unlines and unwords

  • Participants
  • Parent commits b4ed202

Comments (0)

Files changed (1)

File Data/Text.hs

     -- , breakSubstring
 
     -- ** Breaking into lines and words
+    , lines
     , words
-    , lines
+    , unlines
+    , unwords
 
     -- * Predicates
     -- , isPrefixOf
     where search = elemIndex '\n'
 {-# INLINE lines #-}
 
+-- | /O(n)/ Joins lines, after appending a terminating newline to
+-- each.
+unlines :: [Text] -> Text
+unlines = concat . L.map (`snoc` '\n')
+{-# INLINE unlines #-}
+
+-- | /O(n)/ Joins words using single space characters.
+unwords :: [Text] -> Text
+unwords = intercalate (singleton ' ')
+{-# INLINE unwords #-}
+
 errorEmptyList :: String -> a
 errorEmptyList fun = error ("Data.Text." ++ fun ++ ": empty list")