@@ -40,6 +40,7 @@ module Data.Text
4040 , cons
4141 , snoc
4242 , append
43+ , uncons
4344 , head
4445 , last
4546 , tail
@@ -97,7 +98,7 @@ module Data.Text
9798 , zipWith
9899 ) where
99100
100−import Prelude (Char, Bool, Int, Maybe, String,
101+import Prelude (Char, Bool, Int, Maybe(..), String,
101102 Eq, (==), (++), error,
102103 Show, showsPrec,
103104 Read, readsPrec,
@@ -227,6 +228,14 @@ head :: Text -> Char
227228head t = S.head (stream t)
228229{-# INLINE head #-}
229230
231+-- | /O(1)/ Returns the first character and rest of a 'Text', or
232+-- 'Nothing' if empty. Subject to array fusion.
233+uncons :: Text -> Maybe (Char, Text)
234+uncons t = case S.uncons (stream t) of
235+ Just (c, s) -> Just (c, unstream s)
236+ Nothing -> Nothing
237+{-# INLINE uncons #-}
238+
230239-- | /O(n)/ Returns the last character of a 'Text', which must be
231240-- non-empty. Subject to array fusion.
232241last :: Text -> Char