@@ -153,6 +153,7 @@ import Prelude
153153 take, filter, all, any, takeWhile, drop, dropWhile, minimum,
154154 maximum, elem, notElem, null, head, tail, init, zipWith, lookup,
155155 foldr1)
156+import qualified Data.Foldable as F
156157import qualified Prelude
157158
158159import Streamly.SVar
@@ -188,6 +189,20 @@ newtype Stream m a =
188189 -> m r
189190 }
190191
192+instance (Foldable m, Monad m) => Foldable (Stream m) where
193+ {-# INLINE foldMap #-}
194+ foldMap f = F.fold . toFoldable . map f
195+ where
196+ toFoldable :: (Monad m, Monoid a) => Stream m a -> m a
197+ toFoldable = foldr mappend mempty
198+
199+instance (Traversable m, Monad m) => Traversable (Stream m) where
200+ {-# INLINE traverse #-}
201+ traverse f = sequenceA . fmap f
202+
203+ {-# INLINE sequenceA #-}
204+ sequenceA = traverse id
205+
191206-- XXX make this the default "unStream"
192207-- | unwraps the Stream type producing the stream function that can be run with
193208-- continuations.