@@ -22,25 +22,30 @@ module Streamly.Internal.Data.Stream.Serial
2222 (
2323 -- * Serial appending stream
2424 SerialT
25− , StreamT -- deprecated
2625 , Serial
2726 , K.serial
2827 , serially
2928
3029 -- * Serial interleaving stream
3130 , WSerialT
32− , InterleavedT -- deprecated
3331 , WSerial
3432 , wSerial
3533 , wSerialFst
3634 , wSerialMin
37− , (<=>) -- deprecated
3835 , wSerially
39− , interleaving -- deprecated
36+
37+ -- * Construction
38+ , unfoldrM
4039
4140 -- * Transformation
4241 , map
4342 , mapM
43+
44+ -- * Deprecated
45+ , StreamT
46+ , InterleavedT
47+ , (<=>)
48+ , interleaving
4449 )
4550where
4651
@@ -397,3 +402,32 @@ LIST_INSTANCES(WSerialT)
397402NFDATA1_INSTANCE(WSerialT)
398403FOLDABLE_INSTANCE(WSerialT)
399404TRAVERSABLE_INSTANCE(WSerialT)
405+
406+------------------------------------------------------------------------------
407+-- Construction
408+------------------------------------------------------------------------------
409+
410+-- | Build a stream by unfolding a /monadic/ step function starting from a
411+-- seed. The step function returns the next element in the stream and the next
412+-- seed value. When it is done it returns 'Nothing' and the stream ends. For
413+-- example,
414+--
415+-- @
416+-- let f b =
417+-- if b > 3
418+-- then return Nothing
419+-- else print b >> return (Just (b, b + 1))
420+-- in drain $ unfoldrM f 0
421+-- @
422+-- @
423+-- 0
424+-- 1
425+-- 2
426+-- 3
427+-- @
428+--
429+-- /Internal/
430+--
431+{-# INLINE unfoldrM #-}
432+unfoldrM :: Monad m => (b -> m (Maybe (a, b))) -> b -> SerialT m a
433+unfoldrM step seed = D.fromStreamD (D.unfoldrM step seed)