on master help sign in
Implement and test lazy tail

--HG-- extra : convert_revision : 077b516d8b5b0fc44ce8373f604a876b4626e1a9

commitb895b6358aad5918c03e816ada01237579a09b42 authorBryan O'Sullivan <bos@serpentine.com> dateTue 3 Mar 2009, 00:09 (18 years ago) parentd581176
2 files changed+17−3
Data/Text/Lazy.hs+13−1 tests/Properties.hs+4−2
Data/Text/Lazy.hs+13−1
@@ -46,7 +46,7 @@ module Data.Text.Lazy
4646 , uncons
4747 , head
4848 , last
49− -- , tail
49+ , tail
5050 -- , init
5151 -- , null
5252 -- , length
@@ -251,6 +251,18 @@ head :: Text -> Char
251251head t = S.head (stream t)
252252{-# INLINE head #-}
253253
254+tail :: Text -> Text
255+tail (Chunk t ts) = chunk (T.tail t) ts
256+tail Empty = emptyError "tail"
257+{-# INLINE [1] tail #-}
258+
259+{-# RULES
260+"TEXT tail -> fused" [~1] forall t.
261+ tail t = unstream (S.tail (stream t))
262+"TEXT tail -> unfused" [1] forall t.
263+ unstream (S.tail (stream t)) = tail t
264+ #-}
265+
254266-- | /O(1)/ Returns the last character of a 'Text', which must be
255267-- non-empty. Subject to array fusion.
256268last :: Text -> Char
tests/Properties.hs+4−2
@@ -127,8 +127,9 @@ prop_TL_head = head `eqEP` TL.head
127127prop_S_last = last `eqEP` S.last
128128prop_T_last = last `eqEP` T.last
129129prop_TL_last = last `eqEP` TL.last
130+prop_S_tail = tail `eqEP` (unpackT . S.tail)
130131prop_T_tail = tail `eqEP` (unpackT . T.tail)
131−prop_T_tailS = tail `eqEP` (unpackT . S.unstream . S.tail . S.stream)
132+prop_TL_tail = tail `eqEP` (unpackT . TL.tail)
132133prop_T_init = init `eqEP` (unpackT . T.init)
133134prop_T_initS = init `eqEP` (unpackT . S.unstream . S.init . S.stream)
134135prop_T_null = null `eqP` T.null
@@ -304,8 +305,9 @@ tests = [
304305 ("prop_S_last", mytest prop_S_last),
305306 ("prop_T_last", mytest prop_T_last),
306307 ("prop_TL_last", mytest prop_TL_last),
308+ ("prop_S_tail", mytest prop_S_tail),
307309 ("prop_T_tail", mytest prop_T_tail),
308− ("prop_T_tailS", mytest prop_T_tailS),
310+ ("prop_TL_tail", mytest prop_TL_tail),
309311 ("prop_T_init", mytest prop_T_init),
310312 ("prop_T_initS", mytest prop_T_initS),
311313 ("prop_T_null", mytest prop_T_null),