Commits

Bryan O'Sullivan  committed 2eda41a

Implement and test lazy null

  • Participants
  • Parent commits 0c25917

Comments (0)

Files changed (2)

File Data/Text/Lazy.hs

     , last
     , tail
     , init
-    -- , null
+    , null
     -- , length
 
     -- * Transformations
     unstream (S.init (stream t)) = init t
  #-}
 
+-- | /O(1)/ Tests whether a 'Text' is empty or not.  Subject to array
+-- fusion.
+null :: Text -> Bool
+null Empty = True
+null _     = False
+{-# INLINE [1] null #-}
+
+{-# RULES
+"TEXT null -> fused" [~1] forall t.
+    null t = S.null (stream t)
+"TEXT null -> unfused" [1] forall t.
+    S.null (stream t) = null t
+ #-}
+
 -- | /O(1)/ Returns the last character of a 'Text', which must be
 -- non-empty.  Subject to array fusion.
 last :: Text -> Char

File tests/Properties.hs

 prop_S_init            = init   `eqEP` (unpackT . S.init)
 prop_T_init            = init   `eqEP` (unpackT . T.init)
 prop_TL_init           = init   `eqEP` (unpackT . TL.init)
+prop_S_null            = null   `eqP`  S.null
 prop_T_null            = null   `eqP`  T.null
+prop_TL_null           = null   `eqP`  TL.null
 prop_T_length          = length `eqP`  T.length
 prop_T_map f           = map f  `eqP`  (unpackT . T.map f)
 prop_T_intercalate c   = L.intercalate c `eq` (unpackT . T.intercalate (T.pack c) . map T.pack)
   ("prop_S_init", mytest prop_S_init),
   ("prop_T_init", mytest prop_T_init),
   ("prop_TL_init", mytest prop_TL_init),
+  ("prop_S_null", mytest prop_S_null),
   ("prop_T_null", mytest prop_T_null),
+  ("prop_TL_null", mytest prop_TL_null),
   ("prop_T_length", mytest prop_T_length),
 
   ("prop_T_map", mytest prop_T_map),