Commits

Bryan O'Sullivan committed 0027f00

Implement and test lazy tail

Comments (0)

Files changed (2)

Data/Text/Lazy.hs

     , uncons
     , head
     , last
-    -- , tail
+    , tail
     -- , init
     -- , null
     -- , length
 head t = S.head (stream t)
 {-# INLINE head #-}
 
+tail :: Text -> Text
+tail (Chunk t ts) = chunk (T.tail t) ts
+tail Empty        = emptyError "tail"
+{-# INLINE [1] tail #-}
+
+{-# RULES
+"TEXT tail -> fused" [~1] forall t.
+    tail t = unstream (S.tail (stream t))
+"TEXT tail -> unfused" [1] forall t.
+    unstream (S.tail (stream t)) = tail t
+ #-}
+
 -- | /O(1)/ Returns the last character of a 'Text', which must be
 -- non-empty.  Subject to array fusion.
 last :: Text -> Char

tests/Properties.hs

 prop_S_last            = last   `eqEP` S.last
 prop_T_last            = last   `eqEP` T.last
 prop_TL_last           = last   `eqEP` TL.last
+prop_S_tail            = tail   `eqEP` (unpackT . S.tail)
 prop_T_tail            = tail   `eqEP` (unpackT . T.tail)
-prop_T_tailS           = tail   `eqEP` (unpackT . S.unstream . S.tail . S.stream)
+prop_TL_tail           = tail   `eqEP` (unpackT . TL.tail)
 prop_T_init            = init   `eqEP` (unpackT . T.init)
 prop_T_initS           = init   `eqEP` (unpackT . S.unstream . S.init . S.stream)
 prop_T_null            = null   `eqP`  T.null
   ("prop_S_last", mytest prop_S_last),
   ("prop_T_last", mytest prop_T_last),
   ("prop_TL_last", mytest prop_TL_last),
+  ("prop_S_tail", mytest prop_S_tail),
   ("prop_T_tail", mytest prop_T_tail),
-  ("prop_T_tailS", mytest prop_T_tailS),
+  ("prop_TL_tail", mytest prop_TL_tail),
   ("prop_T_init", mytest prop_T_init),
   ("prop_T_initS", mytest prop_T_initS),
   ("prop_T_null", mytest prop_T_null),