@@ -59,6 +59,7 @@ module Streamly.Streams.StreamD
59 -- ** Unfolds
59 -- ** Unfolds
61 , unfoldrM
61 , unfoldrM
63 -- ** Specialized Generation
64 -- ** Specialized Generation
64 -- | Generate a monadic stream from a seed.
65 -- | Generate a monadic stream from a seed.
@@ -392,6 +393,21 @@ unfoldrM next state = Stream step state
392unfoldr :: Monad m => (s -> Maybe (a, s)) -> s -> Stream m a
393unfoldr :: Monad m => (s -> Maybe (a, s)) -> s -> Stream m a
393unfoldr f = unfoldrM (return . f)
394unfoldr f = unfoldrM (return . f)
396+-- | Convert an 'Unfold' into a 'Stream' by supplying it a seed.
398+{-# INLINE_NORMAL unfold #-}
399+unfold :: Monad m => Unfold m a b -> a -> Stream m b
400+unfold (Unfold ustep inject) seed = Stream step Nothing
402+ {-# INLINE_LATE step #-}
403+ step _ Nothing = inject seed >>= return . Skip . Just
404+ step _ (Just st) = do
407+ Yield x s -> Yield x (Just s)
408+ Skip s -> Skip (Just s)
395------------------------------------------------------------------------------
411------------------------------------------------------------------------------
396-- Specialized Generation
412-- Specialized Generation
397------------------------------------------------------------------------------
413------------------------------------------------------------------------------