Commits

Bryan O'Sullivan committed e28de57

Implement and test lazy words

Comments (0)

Files changed (2)

Data/Text/Lazy.hs

 
     -- ** Breaking into lines and words
     , lines
-    --, lines'
-    -- , words
+    , words
     -- , unlines
     -- , unwords
 
 import qualified Prelude as P
 import Data.Int (Int64)
 import qualified Data.List as L
+import Data.Char (isSpace)
 import Data.String (IsString(..))
 import qualified Data.Text as T
 import qualified Data.Text.Fusion.Common as S
           in l : if null t' then []
                  else lines (tail t')
 
+-- | /O(n)/ Breaks a 'Text' up into a list of words, delimited by 'Char's
+-- representing white space.
+words :: Text -> [Text]
+words = L.filter (not . null) . splitWith isSpace
+{-# INLINE words #-}
+
 revChunks :: [T.Text] -> Text
 revChunks = L.foldl' (flip chunk) Empty
 

tests/Properties.hs

           eol c = c == '\r' || c == '\n'
 -}
 prop_T_words           = L.words       `eqP` (map unpackT . T.words)
+prop_TL_words          = L.words       `eqP` (map unpackT . TL.words)
 prop_T_unlines         = L.unlines     `eq`  (unpackT . T.unlines . map T.pack)
 prop_T_unwords         = L.unwords     `eq`  (unpackT . T.unwords . map T.pack)
 
   ("prop_TL_lines", mytest prop_TL_lines),
 --("prop_T_lines'", mytest prop_T_lines'),
   ("prop_T_words", mytest prop_T_words),
+  ("prop_TL_words", mytest prop_TL_words),
   ("prop_T_unlines", mytest prop_T_unlines),
   ("prop_T_unwords", mytest prop_T_unwords),