Build a stream by unfolding a
monadic step function starting
from a seed. The step function returns the next element in the stream
and the next seed value. When it is done it returns
Nothing and
the stream ends. For example,
>>> :{
let f b =
if b > 2
then return Nothing
else return (Just (b, b + 1))
in Stream.toList $ Stream.unfoldrM f 0
:}
[0,1,2]
When run concurrently, the next unfold step can run concurrently with
the processing of the output of the previous step. Note that more than
one step cannot run concurrently as the next step depends on the
output of the previous step.
>>> :{
let f b =
if b > 2
then return Nothing
else threadDelay 1000000 >> return (Just (b, b + 1))
in Stream.toList $ Stream.delay 1 $ Stream.fromAsync $ Stream.unfoldrM f 0
:}
[0,1,2]
Concurrent
Since: 0.1.0