on master help sign in
Added Prelude.null
commiteb5ea090471a1c41d47881afb7a6a3c1be9326f4 authorVeladus <veladus@web.de> dateMon 12 Mar 2018, 18:33 (9 years ago) parent88c1bdf
1 file changed+9−1
src/Streamly/Prelude.hs+9−1
src/Streamly/Prelude.hs+9−1
@@ -41,6 +41,7 @@ module Streamly.Prelude
4141 , head
4242 , tail
4343 , last
44+ , null
4445 , length
4546 , elem
4647 , notElem
@@ -83,7 +84,7 @@ import Prelude hiding (filter, drop, dropWhile, take,
8384 mapM, mapM_, sequence, all, any,
8485 sum, product, elem, notElem,
8586 maximum, minimum, head, last,
86− tail, length)
87+ tail, length, null)
8788import qualified Prelude
8889import qualified System.IO as IO
8990
@@ -347,6 +348,13 @@ tail m =
347348last :: (Streaming t, Monad m) => t m a -> m (Maybe a)
348349last = foldl (\_ y -> Just y) Nothing id
349350
351+-- | Determine wheter the stream is empty
352+null :: (Streaming t, Monad m) => t m a -> m Bool
353+null m =
354+ let stop = return True
355+ yield _ _ = return False
356+ in (runStream (toStream m)) Nothing stop yield
357+
350358-- | Determine whether an element is present in the stream.
351359elem :: (Streaming t, Monad m, Eq a) => a -> t m a -> m Bool
352360elem e m = go (toStream m)