on master help sign in
Implement and test lazy head

--HG-- extra : convert_revision : cbdd5667b97c840d73ea553dac97d25b6966e503

commit99344b7224272749547a74a6124f3df30084f850 authorBryan O'Sullivan <bos@serpentine.com> dateSun 1 Mar 2009, 06:53 (18 years ago) parent6ec2765
2 files changed+11−1
Data/Text/Lazy.hs+7−1 tests/Properties.hs+4
Data/Text/Lazy.hs+7−1
@@ -44,7 +44,7 @@ module Data.Text.Lazy
4444 , snoc
4545 , append
4646 , uncons
47− -- , head
47+ , head
4848 -- , last
4949 -- , tail
5050 -- , init
@@ -244,6 +244,12 @@ uncons (Chunk t ts) =
244244 if T.length t == 1 then ts else Chunk (T.unsafeTail t) ts)
245245{-# INLINE uncons #-}
246246
247+-- | /O(1)/ Returns the first character of a 'Text', which must be
248+-- non-empty. Subject to array fusion.
249+head :: Text -> Char
250+head t = S.head (stream t)
251+{-# INLINE head #-}
252+
247253-- | /O(n)/ 'splitAt' @n t@ returns a pair whose first element is a
248254-- prefix of @t@ of length @n@, and whose second is the remainder of
249255-- the string. It is equivalent to @('take' n t, 'drop' n t)@.
tests/Properties.hs+4
@@ -121,7 +121,9 @@ prop_T_uncons s = uncons `eqP` (fmap (second unpackT) . T.uncons)
121121 where types = s :: String
122122prop_TL_uncons s = uncons `eqP` (fmap (second unpackT) . TL.uncons)
123123 where types = s :: String
124+prop_S_head = head `eqEP` S.head
124125prop_T_head = head `eqEP` T.head
126+prop_TL_head = head `eqEP` TL.head
125127prop_T_last = last `eqEP` T.last
126128prop_T_lastS = last `eqEP` (S.last . S.stream)
127129prop_T_tail = tail `eqEP` (unpackT . T.tail)
@@ -295,7 +297,9 @@ tests = [
295297 ("prop_T_appendS", mytest prop_T_appendS),
296298 ("prop_T_uncons", mytest prop_T_uncons),
297299 ("prop_TL_uncons", mytest prop_TL_uncons),
300+ ("prop_S_head", mytest prop_S_head),
298301 ("prop_T_head", mytest prop_T_head),
302+ ("prop_TL_head", mytest prop_TL_head),
299303 ("prop_T_last", mytest prop_T_last),
300304 ("prop_T_lastS", mytest prop_T_lastS),
301305 ("prop_T_tail", mytest prop_T_tail),