From eb5ea090471a1c41d47881afb7a6a3c1be9326f4 Mon Sep 17 00:00:00 2001 From: Veladus Date: Mon, 12 Mar 2018 18:33:38 +0100 Subject: [PATCH] Added Prelude.null --- src/Streamly/Prelude.hs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Streamly/Prelude.hs b/src/Streamly/Prelude.hs index 7ce004318..014689ce0 100644 --- a/src/Streamly/Prelude.hs +++ b/src/Streamly/Prelude.hs @@ -41,6 +41,7 @@ module Streamly.Prelude , head , tail , last + , null , length , elem , notElem @@ -83,7 +84,7 @@ import Prelude hiding (filter, drop, dropWhile, take, mapM, mapM_, sequence, all, any, sum, product, elem, notElem, maximum, minimum, head, last, - tail, length) + tail, length, null) import qualified Prelude import qualified System.IO as IO @@ -347,6 +348,13 @@ tail m = last :: (Streaming t, Monad m) => t m a -> m (Maybe a) last = foldl (\_ y -> Just y) Nothing id +-- | Determine wheter the stream is empty +null :: (Streaming t, Monad m) => t m a -> m Bool +null m = + let stop = return True + yield _ _ = return False + in (runStream (toStream m)) Nothing stop yield + -- | Determine whether an element is present in the stream. elem :: (Streaming t, Monad m, Eq a) => a -> t m a -> m Bool elem e m = go (toStream m)