Commits

Bryan O'Sullivan committed 676d7db

Implement and test lazy lines

Comments (0)

Files changed (2)

Data/Text/Lazy.hs

     -- , breakSubstring
 
     -- ** Breaking into lines and words
-    -- , lines
+    , lines
     --, lines'
     -- , words
     -- , unlines
         comb acc (s:ss) ts           = revChunks (s:acc) : comb [] ss ts
 {-# INLINE splitWith #-}
 
+-- | /O(n)/ Breaks a 'Text' up into a list of 'Text's at
+-- newline 'Char's. The resulting strings do not contain newlines.
+lines :: Text -> [Text]
+lines Empty = []
+lines t = let (l,t') = break ((==) '\n') t
+          in l : if null t' then []
+                 else lines (tail t')
+
 revChunks :: [T.Text] -> Text
 revChunks = L.foldl' (flip chunk) Empty
 

tests/Properties.hs

                        (unpack2 . T.breakSubstring (T.singleton c))
 
 prop_T_lines           = L.lines       `eqP` (map unpackT . T.lines)
+prop_TL_lines          = L.lines       `eqP` (map unpackT . TL.lines)
 {-
 prop_T_lines'          = lines'        `eqP` (map unpackT . T.lines')
     where lines' "" =  []
   ("prop_T_breakSubstring_isInfixOf", mytest prop_T_breakSubstring_isInfixOf),
 
   ("prop_T_lines", mytest prop_T_lines),
+  ("prop_TL_lines", mytest prop_TL_lines),
 --("prop_T_lines'", mytest prop_T_lines'),
   ("prop_T_words", mytest prop_T_words),
   ("prop_T_unlines", mytest prop_T_unlines),