on master help sign in
Added Prelude.null
eb5ea09Veladus
src/Streamly/Prelude.hs+9−1
@@ -41,6 +41,7 @@ module Streamly.Prelude
41 , head
41 , head
42 , tail
42 , tail
43 , last
43 , last
44+ , null
44 , length
45 , length
45 , elem
46 , elem
46 , notElem
47 , notElem
@@ -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
89
90
@@ -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
349
350
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+
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)