on master help sign in
Update doc for monadic bind operations
5f1a552Harendra Kumar
src/Asyncly/AsyncT.hs+17−11
@@ -126,7 +126,8 @@ type MonadAsync m = (MonadIO m, MonadBaseControl IO m, MonadThrow m)
126-- Monoid
126-- Monoid
127------------------------------------------------------------------------------
127------------------------------------------------------------------------------
128
128
129−-- | '<>' concatenates two 'AsyncT' streams sequentially.
129+-- | '<>' concatenates two 'AsyncT' streams sequentially i.e. the first stream
130+-- is exhausted completely before yielding any element from the second stream.
130instance Semigroup (AsyncT m a) where
131instance Semigroup (AsyncT m a) where
131 m1 <> m2 = go m1
132 m1 <> m2 = go m1
132 where
133 where
@@ -150,8 +151,9 @@ interleave m1 m2 = AsyncT $ \ctx stp yld -> do
150
151
151infixr 5 <=>
152infixr 5 <=>
152
153
153−-- | Sequential compostion, similar to '<>' except that it interleaves the two
154+-- | Sequential interleaved composition, similar to '<>' except that it
154−-- 'AsyncT' streams fairly.
155+-- fairly interleaves the two 'AsyncT' streams, yielding an element from each
156+-- stream alternately.
155(<=>) :: AsyncT m a -> AsyncT m a -> AsyncT m a
157(<=>) :: AsyncT m a -> AsyncT m a -> AsyncT m a
156(<=>) = interleave
158(<=>) = interleave
157
159
@@ -198,8 +200,10 @@ bindWith k m f = go m
198 yield a _ (Just r) = run $ f a `k` (go r)
200 yield a _ (Just r) = run $ f a `k` (go r)
199 in g Nothing stp yield
201 in g Nothing stp yield
200
202
201−-- | '>>=' runs a monadic action for each element in the stream, sequentially,
203+-- | '>>=' execute a monadic action for each element generated by the 'AsyncT'
202−-- in a depth first manner.
204+-- stream, running nested loops sequentially, in a depth first manner i.e. the
205+-- inner loop finishes completely before the next iteration of the outer loop
206+-- can run.
203instance Monad m => Monad (AsyncT m) where
207instance Monad m => Monad (AsyncT m) where
204 return = pure
208 return = pure
205
209
@@ -213,18 +217,20 @@ instance Monad m => Monad (AsyncT m) where
213-- Alternative ways to bind
217-- Alternative ways to bind
214------------------------------------------------------------------------------
218------------------------------------------------------------------------------
215
219
216−-- | Run a monadic action for each element in the stream, sequentially, in a
220+-- | Execute a monadic action for each element in the stream, running nested
217−-- breadth first manner i.e. fairly interleaved.
221+-- loops sequentially, but in a fairly interleaved manner i.e. both inner and
222+-- outer loop yield alternately.
218(>->) :: AsyncT m a -> (a -> AsyncT m b) -> AsyncT m b
223(>->) :: AsyncT m a -> (a -> AsyncT m b) -> AsyncT m b
219(>->) = bindWith (<=>)
224(>->) = bindWith (<=>)
220
225
221−-- | Run a monadic action for each element in the stream, in parallel, with
226+-- | Execute a monadic action for each element in the stream, running nested
222−-- a depth first bias.
227+-- loops in parallel, but with a depth first preference.
223(>>|) :: MonadAsync m => AsyncT m a -> (a -> AsyncT m b) -> AsyncT m b
228(>>|) :: MonadAsync m => AsyncT m a -> (a -> AsyncT m b) -> AsyncT m b
224(>>|) = bindWith (<|)
229(>>|) = bindWith (<|)
225
230
226−-- | Run a monadic action for each element in the stream, in parallel, with a
231+-- | Execute a monadic action for each element in the stream, running nested
227−-- breadth first bias i.e. fairly interleaved.
232+-- loops in parallel, but in a fairly interleaved manner i.e. both inner and
233+-- outer loops yield alternately.
228(>|>) :: MonadAsync m => AsyncT m a -> (a -> AsyncT m b) -> AsyncT m b
234(>|>) :: MonadAsync m => AsyncT m a -> (a -> AsyncT m b) -> AsyncT m b
229(>|>) = bindWith (<|>)
235(>|>) = bindWith (<|>)
230
236