@@ -39,6 +39,7 @@ module Streamly.Prelude
@@ -82,7 +83,7 @@ import Prelude hiding (filter, drop, dropWhile, take,
82 mapM, mapM_, sequence, all, any,
83 mapM, mapM_, sequence, all, any,
83 sum, product, elem, notElem,
84 sum, product, elem, notElem,
84 maximum, minimum, head, last,
85 maximum, minimum, head, last,
85− length)
86+ tail, length)
86import qualified Prelude
87import qualified Prelude
87import qualified System.IO as IO
88import qualified System.IO as IO
@@ -333,6 +334,14 @@ head m =
333 yield a _ = return (Just a)
334 yield a _ = return (Just a)
334 in (runStream (toStream m)) Nothing stop yield
335 in (runStream (toStream m)) Nothing stop yield
337+-- | Extract all but the first element of the stream, if any.
338+tail :: (Streaming t, Monad m) => t m a -> m (Maybe (t m a))
340+ let stop = return Nothing
341+ yield _ Nothing = return $ Just nil
342+ yield _ (Just t) = return $ Just $ fromStream t
343+ in (runStream (toStream m)) Nothing stop yield
336-- | Extract the last element of the stream, if any.
345-- | Extract the last element of the stream, if any.
337{-# INLINE last #-}
346{-# INLINE last #-}
338last :: (Streaming t, Monad m) => t m a -> m (Maybe a)
347last :: (Streaming t, Monad m) => t m a -> m (Maybe a)