on master help sign in
Implement and test lazy null

--HG-- extra : convert_revision : cfb59bebe42d1949c0d7cb46fb1905fe7febd664

commit8396390d23e25d11859bb003b741889b6cf4176c authorBryan O'Sullivan <bos@serpentine.com> dateTue 3 Mar 2009, 00:18 (18 years ago) parent95b326b
2 files changed+19−1
Data/Text/Lazy.hs+15−1 tests/Properties.hs+4
Data/Text/Lazy.hs+15−1
@@ -48,7 +48,7 @@ module Data.Text.Lazy
4848 , last
4949 , tail
5050 , init
51− -- , null
51+ , null
5252 -- , length
5353
5454 -- * Transformations
@@ -279,6 +279,20 @@ init Empty = emptyError "init"
279279 unstream (S.init (stream t)) = init t
280280 #-}
281281
282+-- | /O(1)/ Tests whether a 'Text' is empty or not. Subject to array
283+-- fusion.
284+null :: Text -> Bool
285+null Empty = True
286+null _ = False
287+{-# INLINE [1] null #-}
288+
289+{-# RULES
290+"TEXT null -> fused" [~1] forall t.
291+ null t = S.null (stream t)
292+"TEXT null -> unfused" [1] forall t.
293+ S.null (stream t) = null t
294+ #-}
295+
282296-- | /O(1)/ Returns the last character of a 'Text', which must be
283297-- non-empty. Subject to array fusion.
284298last :: Text -> Char
tests/Properties.hs+4
@@ -133,7 +133,9 @@ prop_TL_tail = tail `eqEP` (unpackT . TL.tail)
133133prop_S_init = init `eqEP` (unpackT . S.init)
134134prop_T_init = init `eqEP` (unpackT . T.init)
135135prop_TL_init = init `eqEP` (unpackT . TL.init)
136+prop_S_null = null `eqP` S.null
136137prop_T_null = null `eqP` T.null
138+prop_TL_null = null `eqP` TL.null
137139prop_T_length = length `eqP` T.length
138140prop_T_map f = map f `eqP` (unpackT . T.map f)
139141prop_T_intercalate c = L.intercalate c `eq` (unpackT . T.intercalate (T.pack c) . map T.pack)
@@ -312,7 +314,9 @@ tests = [
312314 ("prop_S_init", mytest prop_S_init),
313315 ("prop_T_init", mytest prop_T_init),
314316 ("prop_TL_init", mytest prop_TL_init),
317+ ("prop_S_null", mytest prop_S_null),
315318 ("prop_T_null", mytest prop_T_null),
319+ ("prop_TL_null", mytest prop_TL_null),
316320 ("prop_T_length", mytest prop_T_length),
317321
318322 ("prop_T_map", mytest prop_T_map),