@@ -39,6 +39,7 @@ module Streamly.Prelude
3939 , all
4040 , any
4141 , head
42+ , tail
4243 , last
4344 , length
4445 , elem
@@ -82,7 +83,7 @@ import Prelude hiding (filter, drop, dropWhile, take,
8283 mapM, mapM_, sequence, all, any,
8384 sum, product, elem, notElem,
8485 maximum, minimum, head, last,
85− length)
86+ tail, length)
8687import qualified Prelude
8788import qualified System.IO as IO
8889
@@ -333,6 +334,14 @@ head m =
333334 yield a _ = return (Just a)
334335 in (runStream (toStream m)) Nothing stop yield
335336
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))
339+tail m =
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
344+
336345-- | Extract the last element of the stream, if any.
337346{-# INLINE last #-}
338347last :: (Streaming t, Monad m) => t m a -> m (Maybe a)