on master help sign in
Implement and test lazy tail
b895b63Bryan O'Sullivan
Data/Text/Lazy.hs+13−1
@@ -46,7 +46,7 @@ module Data.Text.Lazy
46 , uncons
46 , uncons
47 , head
47 , head
48 , last
48 , last
49− -- , tail
49+ , tail
50 -- , init
50 -- , init
51 -- , null
51 -- , null
52 -- , length
52 -- , length
@@ -251,6 +251,18 @@ head :: Text -> Char
251head t = S.head (stream t)
251head t = S.head (stream t)
252{-# INLINE head #-}
252{-# INLINE head #-}
253
253
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+
254-- | /O(1)/ Returns the last character of a 'Text', which must be
266-- | /O(1)/ Returns the last character of a 'Text', which must be
255-- non-empty. Subject to array fusion.
267-- non-empty. Subject to array fusion.
256last :: Text -> Char
268last :: Text -> Char
tests/Properties.hs+4−2
@@ -127,8 +127,9 @@ prop_TL_head = head `eqEP` TL.head
127prop_S_last = last `eqEP` S.last
127prop_S_last = last `eqEP` S.last
128prop_T_last = last `eqEP` T.last
128prop_T_last = last `eqEP` T.last
129prop_TL_last = last `eqEP` TL.last
129prop_TL_last = last `eqEP` TL.last
130+prop_S_tail = tail `eqEP` (unpackT . S.tail)
130prop_T_tail = tail `eqEP` (unpackT . T.tail)
131prop_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)
132prop_T_init = init `eqEP` (unpackT . T.init)
133prop_T_init = init `eqEP` (unpackT . T.init)
133prop_T_initS = init `eqEP` (unpackT . S.unstream . S.init . S.stream)
134prop_T_initS = init `eqEP` (unpackT . S.unstream . S.init . S.stream)
134prop_T_null = null `eqP` T.null
135prop_T_null = null `eqP` T.null
@@ -304,8 +305,9 @@ tests = [
304 ("prop_S_last", mytest prop_S_last),
305 ("prop_S_last", mytest prop_S_last),
305 ("prop_T_last", mytest prop_T_last),
306 ("prop_T_last", mytest prop_T_last),
306 ("prop_TL_last", mytest prop_TL_last),
307 ("prop_TL_last", mytest prop_TL_last),
308+ ("prop_S_tail", mytest prop_S_tail),
307 ("prop_T_tail", mytest prop_T_tail),
309 ("prop_T_tail", mytest prop_T_tail),
308− ("prop_T_tailS", mytest prop_T_tailS),
310+ ("prop_TL_tail", mytest prop_TL_tail),
309 ("prop_T_init", mytest prop_T_init),
311 ("prop_T_init", mytest prop_T_init),
310 ("prop_T_initS", mytest prop_T_initS),
312 ("prop_T_initS", mytest prop_T_initS),
311 ("prop_T_null", mytest prop_T_null),
313 ("prop_T_null", mytest prop_T_null),