@@ -153,6 +153,7 @@ import Prelude
153 take, filter, all, any, takeWhile, drop, dropWhile, minimum,
153 take, filter, all, any, takeWhile, drop, dropWhile, minimum,
154 maximum, elem, notElem, null, head, tail, init, zipWith, lookup,
154 maximum, elem, notElem, null, head, tail, init, zipWith, lookup,
156+import qualified Data.Foldable as F
156import qualified Prelude
157import qualified Prelude
158import Streamly.SVar
159import Streamly.SVar
@@ -188,6 +189,20 @@ newtype Stream m a =
192+instance (Foldable m, Monad m) => Foldable (Stream m) where
193+ {-# INLINE foldMap #-}
194+ foldMap f = F.fold . toFoldable . map f
196+ toFoldable :: (Monad m, Monoid a) => Stream m a -> m a
197+ toFoldable = foldr mappend mempty
199+instance (Traversable m, Monad m) => Traversable (Stream m) where
200+ {-# INLINE traverse #-}
201+ traverse f = sequenceA . fmap f
203+ {-# INLINE sequenceA #-}
204+ sequenceA = traverse id
191-- XXX make this the default "unStream"
206-- XXX make this the default "unStream"
192-- | unwraps the Stream type producing the stream function that can be run with
207-- | unwraps the Stream type producing the stream function that can be run with
193-- continuations.
208-- continuations.