mirror of
https://github.com/composewell/streamly.git
synced 2024-09-21 08:31:42 +03:00
Added Prelude.tail
This commit is contained in:
parent
29bc664825
commit
88c1bdf209
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user