on master help sign in
Implement and test lazy words
184a502Bryan O'Sullivan
Data/Text/Lazy.hs+8−2
@@ -115,8 +115,7 @@ module Data.Text.Lazy
115
115
116 -- ** Breaking into lines and words
116 -- ** Breaking into lines and words
117 , lines
117 , lines
118− --, lines'
119− -- , words
118+ , words
120 -- , unlines
119 -- , unlines
121 -- , unwords
120 -- , unwords
122
121
@@ -156,6 +155,7 @@ import Prelude (Char, Bool(..), Functor(..), Int, Maybe(..), String,
156import qualified Prelude as P
155import qualified Prelude as P
157import Data.Int (Int64)
156import Data.Int (Int64)
158import qualified Data.List as L
157import qualified Data.List as L
158+import Data.Char (isSpace)
159import Data.String (IsString(..))
159import Data.String (IsString(..))
160import qualified Data.Text as T
160import qualified Data.Text as T
161import qualified Data.Text.Fusion.Common as S
161import qualified Data.Text.Fusion.Common as S
@@ -725,6 +725,12 @@ lines t = let (l,t') = break ((==) '\n') t
725 in l : if null t' then []
725 in l : if null t' then []
726 else lines (tail t')
726 else lines (tail t')
727
727
728+-- | /O(n)/ Breaks a 'Text' up into a list of words, delimited by 'Char's
729+-- representing white space.
730+words :: Text -> [Text]
731+words = L.filter (not . null) . splitWith isSpace
732+{-# INLINE words #-}
733+
728revChunks :: [T.Text] -> Text
734revChunks :: [T.Text] -> Text
729revChunks = L.foldl' (flip chunk) Empty
735revChunks = L.foldl' (flip chunk) Empty
730
736
tests/Properties.hs+2
@@ -294,6 +294,7 @@ prop_T_lines' = lines' `eqP` (map unpackT . T.lines')
294 eol c = c == '\r' || c == '\n'
294 eol c = c == '\r' || c == '\n'
295-}
295-}
296prop_T_words = L.words `eqP` (map unpackT . T.words)
296prop_T_words = L.words `eqP` (map unpackT . T.words)
297+prop_TL_words = L.words `eqP` (map unpackT . TL.words)
297prop_T_unlines = L.unlines `eq` (unpackT . T.unlines . map T.pack)
298prop_T_unlines = L.unlines `eq` (unpackT . T.unlines . map T.pack)
298prop_T_unwords = L.unwords `eq` (unpackT . T.unwords . map T.pack)
299prop_T_unwords = L.unwords `eq` (unpackT . T.unwords . map T.pack)
299
300
@@ -488,6 +489,7 @@ tests = [
488 ("prop_TL_lines", mytest prop_TL_lines),
489 ("prop_TL_lines", mytest prop_TL_lines),
489--("prop_T_lines'", mytest prop_T_lines'),
490--("prop_T_lines'", mytest prop_T_lines'),
490 ("prop_T_words", mytest prop_T_words),
491 ("prop_T_words", mytest prop_T_words),
492+ ("prop_TL_words", mytest prop_TL_words),
491 ("prop_T_unlines", mytest prop_T_unlines),
493 ("prop_T_unlines", mytest prop_T_unlines),
492 ("prop_T_unwords", mytest prop_T_unwords),
494 ("prop_T_unwords", mytest prop_T_unwords),
493
495