For AheadT streams:
(<>) = Streamly.Prelude.ahead
(>>=) = flip . Streamly.Prelude.concatMapWith Streamly.Prelude.ahead
A single Monad bind behaves like a for loop with iterations executed
concurrently, ahead of time, producing side effects of iterations out of
order, but results in order:
:{Stream.toList $ Stream.fromAhead $ do x <- Stream.fromList [2,1] -- foreach x in stream Stream.fromEffect $ delay x:}1 sec2 sec[2,1]
Nested monad binds behave like nested for loops with nested iterations
executed concurrently, ahead of time:
:{Stream.toList $ Stream.fromAhead $ 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,5,4,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 ahead.
Since: 0.3.0 (Streamly)
Instances10IsStream, MonadReader, MonadState, Monad, Functor, Applicative, …
IsStream AheadTDefined in streamly-0.10.1 · Streamly.Internal.Data.Stream.IsStream.Type(MonadReader r m, MonadAsync m) => MonadReader r (AheadT m)Defined in streamly-0.10.1 · Streamly.Internal.Data.Stream.Ahead(MonadState s m, MonadAsync m) => MonadState s (AheadT m)Defined in streamly-0.10.1 · Streamly.Internal.Data.Stream.AheadMonadAsync m => Monad (AheadT m)Defined in streamly-0.10.1 · Streamly.Internal.Data.Stream.AheadMonad m => Functor (AheadT m)Defined in streamly-0.10.1 · Streamly.Internal.Data.Stream.Ahead(Monad m, MonadAsync m) => Applicative (AheadT m)Defined in streamly-0.10.1 · Streamly.Internal.Data.Stream.Ahead(MonadIO m, MonadAsync m) => MonadIO (AheadT m)Defined in streamly-0.10.1 · Streamly.Internal.Data.Stream.Ahead(MonadThrow m, MonadAsync m) => MonadThrow (AheadT m)Defined in streamly-0.10.1 · Streamly.Internal.Data.Stream.AheadMonadAsync m => Semigroup (AheadT m a)Defined in streamly-0.10.1 · Streamly.Internal.Data.Stream.AheadMonadAsync m => Monoid (AheadT m a)Defined in streamly-0.10.1 · Streamly.Internal.Data.Stream.Ahead