@@ -41,6 +41,7 @@ module Streamly.Prelude
@@ -83,7 +84,7 @@ import Prelude hiding (filter, drop, dropWhile, take,
83 mapM, mapM_, sequence, all, any,
84 mapM, mapM_, sequence, all, any,
84 sum, product, elem, notElem,
85 sum, product, elem, notElem,
85 maximum, minimum, head, last,
86 maximum, minimum, head, last,
86− tail, length)
87+ tail, length, null)
87import qualified Prelude
88import qualified Prelude
88import qualified System.IO as IO
89import qualified System.IO as IO
@@ -347,6 +348,13 @@ tail m =
347last :: (Streaming t, Monad m) => t m a -> m (Maybe a)
348last :: (Streaming t, Monad m) => t m a -> m (Maybe a)
348last = foldl (\_ y -> Just y) Nothing id
349last = foldl (\_ y -> Just y) Nothing id
351+-- | Determine wheter the stream is empty
352+null :: (Streaming t, Monad m) => t m a -> m Bool
354+ let stop = return True
355+ yield _ _ = return False
356+ in (runStream (toStream m)) Nothing stop yield
350-- | Determine whether an element is present in the stream.
358-- | Determine whether an element is present in the stream.
351elem :: (Streaming t, Monad m, Eq a) => a -> t m a -> m Bool
359elem :: (Streaming t, Monad m, Eq a) => a -> t m a -> m Bool
352elem e m = go (toStream m)
360elem e m = go (toStream m)