Commits

Bryan O'Sullivan  committed f2be691

Implement and test lazy head

  • Participants
  • Parent commits fba844e

Comments (0)

Files changed (2)

File Data/Text/Lazy.hs

     , snoc
     , append
     , uncons
-    -- , head
+    , head
     -- , last
     -- , tail
     -- , init
           if T.length t == 1 then ts else Chunk (T.unsafeTail t) ts)
 {-# INLINE uncons #-}
 
+-- | /O(1)/ Returns the first character of a 'Text', which must be
+-- non-empty.  Subject to array fusion.
+head :: Text -> Char
+head t = S.head (stream t)
+{-# INLINE head #-}
+
 -- | /O(n)/ 'splitAt' @n t@ returns a pair whose first element is a
 -- prefix of @t@ of length @n@, and whose second is the remainder of
 -- the string. It is equivalent to @('take' n t, 'drop' n t)@.

File tests/Properties.hs

     where types = s :: String
 prop_TL_uncons s       = uncons   `eqP` (fmap (second unpackT) . TL.uncons)
     where types = s :: String
+prop_S_head            = head   `eqEP` S.head
 prop_T_head            = head   `eqEP` T.head
+prop_TL_head           = head   `eqEP` TL.head
 prop_T_last            = last   `eqEP` T.last
 prop_T_lastS           = last   `eqEP` (S.last . S.stream)
 prop_T_tail            = tail   `eqEP` (unpackT . T.tail)
   ("prop_T_appendS", mytest prop_T_appendS),
   ("prop_T_uncons", mytest prop_T_uncons),
   ("prop_TL_uncons", mytest prop_TL_uncons),
+  ("prop_S_head", mytest prop_S_head),
   ("prop_T_head", mytest prop_T_head),
+  ("prop_TL_head", mytest prop_TL_head),
   ("prop_T_last", mytest prop_T_last),
   ("prop_T_lastS", mytest prop_T_lastS),
   ("prop_T_tail", mytest prop_T_tail),