For AsyncT streams:
(<>) = Streamly.Prelude.async
(>>=) = flip . Streamly.Prelude.concatMapWith Streamly.Prelude.async
A single Monad bind behaves like a for loop with iterations of the loop
executed concurrently a la the async combinator, producing results and
side effects of iterations out of order:
:{Stream.toList $ Stream.fromAsync $ do x <- Stream.fromList [2,1] -- foreach x in stream Stream.fromEffect $ delay x:}1 sec2 sec[1,2]
Nested monad binds behave like nested for loops with nested iterations
executed concurrently, a la the async combinator:
:{Stream.toList $ Stream.fromAsync $ do x <- Stream.fromList [1,2] -- foreach x in stream y <- Stream.fromList [2,4] -- foreach y in stream Stream.fromEffect $ delay (x + y):}3 sec4 sec5 sec6 sec[3,4,5,6]
The behavior can be explained as follows. All the iterations corresponding
to the element 1 in the first stream constitute one output stream and all
the iterations corresponding to 2 constitute another output stream and
these two output streams are merged using async.
Since: 0.1.0 (Streamly)
Instances10IsStream, MonadReader, MonadState, Monad, Functor, Applicative, …
IsStream AsyncTDefined in streamly-0.10.1 · Streamly.Internal.Data.Stream.IsStream.Type(MonadReader r m, MonadAsync m) => MonadReader r (AsyncT m)Defined in streamly-0.10.1 · Streamly.Internal.Data.Stream.Async(MonadState s m, MonadAsync m) => MonadState s (AsyncT m)Defined in streamly-0.10.1 · Streamly.Internal.Data.Stream.AsyncMonadAsync m => Monad (AsyncT m)Defined in streamly-0.10.1 · Streamly.Internal.Data.Stream.AsyncMonad m => Functor (AsyncT m)Defined in streamly-0.10.1 · Streamly.Internal.Data.Stream.Async(Monad m, MonadAsync m) => Applicative (AsyncT m)Defined in streamly-0.10.1 · Streamly.Internal.Data.Stream.Async(MonadIO m, MonadAsync m) => MonadIO (AsyncT m)Defined in streamly-0.10.1 · Streamly.Internal.Data.Stream.Async(MonadThrow m, MonadAsync m) => MonadThrow (AsyncT m)Defined in streamly-0.10.1 · Streamly.Internal.Data.Stream.AsyncMonadAsync m => Semigroup (AsyncT m a)Defined in streamly-0.10.1 · Streamly.Internal.Data.Stream.AsyncMonadAsync m => Monoid (AsyncT m a)Defined in streamly-0.10.1 · Streamly.Internal.Data.Stream.Async