From 88c1bdf209e31f3e24ada38c05d0d4dc151cd644 Mon Sep 17 00:00:00 2001 From: Veladus Date: Mon, 12 Mar 2018 18:14:46 +0100 Subject: [PATCH] Added Prelude.tail --- src/Streamly/Prelude.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Streamly/Prelude.hs b/src/Streamly/Prelude.hs index 8e919ad35..7ce004318 100644 --- a/src/Streamly/Prelude.hs +++ b/src/Streamly/Prelude.hs @@ -39,6 +39,7 @@ module Streamly.Prelude , all , any , head + , tail , last , length , elem @@ -82,7 +83,7 @@ import Prelude hiding (filter, drop, dropWhile, take, mapM, mapM_, sequence, all, any, sum, product, elem, notElem, maximum, minimum, head, last, - length) + tail, length) import qualified Prelude import qualified System.IO as IO @@ -333,6 +334,14 @@ head m = yield a _ = return (Just a) in (runStream (toStream m)) Nothing stop yield +-- | Extract all but the first element of the stream, if any. +tail :: (Streaming t, Monad m) => t m a -> m (Maybe (t m a)) +tail m = + let stop = return Nothing + yield _ Nothing = return $ Just nil + yield _ (Just t) = return $ Just $ fromStream t + in (runStream (toStream m)) Nothing stop yield + -- | Extract the last element of the stream, if any. {-# INLINE last #-} last :: (Streaming t, Monad m) => t m a -> m (Maybe a)