@@ -55,6 +55,7 @@ module Streamly.Prelude
56 , iterateM
56 , iterateM
57 , fromFoldable
57 , fromFoldable
59 -- * Deconstruction
60 -- * Deconstruction
@@ -145,6 +146,7 @@ import Streamly.Streams
145-- | Build a Stream by unfolding pure steps starting from a seed.
146-- | Build a Stream by unfolding pure steps starting from a seed.
147-- @since 0.1.0
148-- @since 0.1.0
149+{-# INLINE unfoldr #-}
148unfoldr :: IsStream t => (b -> Maybe (a, b)) -> b -> t m a
150unfoldr :: IsStream t => (b -> Maybe (a, b)) -> b -> t m a
149unfoldr step = fromStream . go
151unfoldr step = fromStream . go
@@ -156,6 +158,7 @@ unfoldr step = fromStream . go
156-- | Build a Stream by unfolding monadic steps starting from a seed.
158-- | Build a Stream by unfolding monadic steps starting from a seed.
158-- @since 0.1.0
160-- @since 0.1.0
161+{-# INLINE unfoldrM #-}
159unfoldrM :: (IsStream t, Monad m) => (b -> m (Maybe (a, b))) -> b -> t m a
162unfoldrM :: (IsStream t, Monad m) => (b -> m (Maybe (a, b))) -> b -> t m a
160unfoldrM step = fromStream . go
163unfoldrM step = fromStream . go
@@ -165,13 +168,20 @@ unfoldrM step = fromStream . go
165 Nothing -> stp
168 Nothing -> stp
166 Just (a, b) -> yld a (go b)
169 Just (a, b) -> yld a (go b)
168−-- | Construct a stream from a 'Foldable' container.
171+-- | Construct a stream from a 'Foldable' containing pure values.
170-- @since 0.2.0
173-- @since 0.2.0
171{-# INLINE fromFoldable #-}
174{-# INLINE fromFoldable #-}
172fromFoldable :: (IsStream t, Foldable f) => f a -> t m a
175fromFoldable :: (IsStream t, Foldable f) => f a -> t m a
173fromFoldable = Prelude.foldr cons nil
176fromFoldable = Prelude.foldr cons nil
178+-- | Construct a stream from a 'Foldable' containing monadic actions.
181+{-# INLINE fromFoldableM #-}
182+fromFoldableM :: (IsStream t, Monad m, Foldable f) => f (m a) -> t m a
183+fromFoldableM = Prelude.foldr consM nil
175-- | Same as 'fromFoldable'.
185-- | Same as 'fromFoldable'.
177-- @since 0.1.0
187-- @since 0.1.0
@@ -294,7 +304,8 @@ foldrM step acc m = go (toStream m)
294-- @since 0.2.0
304-- @since 0.2.0
295{-# INLINE scanx #-}
305{-# INLINE scanx #-}
296scanx :: IsStream t => (x -> a -> x) -> x -> (x -> b) -> t m a -> t m b
306scanx :: IsStream t => (x -> a -> x) -> x -> (x -> b) -> t m a -> t m b
307+scanx step begin done m =
297−scanx step begin done m = cons (done begin) $ fromStream $ go (toStream m) begin
308+ cons (done begin) $ fromStream $ go (toStream m) begin
299 go m1 !acc = Stream $ \_ stp sng yld ->
310 go m1 !acc = Stream $ \_ stp sng yld ->
300 let single a = sng (done $ step acc a)
311 let single a = sng (done $ step acc a)