on master help sign in
make docs of unfoldrM and iterateM more precise
c3a5ef2Harendra Kumar
src/Streamly/Prelude.hs+10−3
@@ -191,8 +191,10 @@ unfoldr step = fromStream . go
191-- 2
191-- 2
192-- 3
192-- 3
193-- @
193-- @
194−-- When run concurrently, the next unfold can run concurrently while previously
194+-- When run concurrently, the next unfold step can run concurrently with the
195−-- generated value is being processed by the next stream stage.
195+-- processing of the output of the previous step. Note that more than one step
196+-- cannot run concurrently as the next step depends on the output of the
197+-- previous step.
196--
198--
197-- @
199-- @
198-- (asyncly $ S.unfoldrM (\\n -> liftIO (threadDelay 1000000) >> return (Just (n, n + 1))) 0)
200-- (asyncly $ S.unfoldrM (\\n -> liftIO (threadDelay 1000000) >> return (Just (n, n + 1))) 0)
@@ -296,6 +298,11 @@ iterate step = fromStream . go
296-- | Iterate a monadic function from a seed value, streaming the results
298-- | Iterate a monadic function from a seed value, streaming the results
297-- forever.
299-- forever.
298--
300--
301+-- When run concurrently, the next iteration can run concurrently with the
302+-- processing of the previous iteration. Note that more than one iteration
303+-- cannot run concurrently as the next iteration depends on the output of the
304+-- previous iteration.
305+--
299-- @
306-- @
300-- runStream $ serially $ S.take 10 $ S.iterateM
307-- runStream $ serially $ S.take 10 $ S.iterateM
301-- (\\x -> threadDelay 1000000 >> print x >> return (x + 1)) 0
308-- (\\x -> threadDelay 1000000 >> print x >> return (x + 1)) 0
@@ -304,7 +311,7 @@ iterate step = fromStream . go
304-- (\\x -> threadDelay 1000000 >> print x >> return (x + 1)) 0
311-- (\\x -> threadDelay 1000000 >> print x >> return (x + 1)) 0
305-- @
312-- @
306--
313--
307−-- /Concurrent, infinite (do not use with 'parallely')/
314+-- /Concurrent/
308--
315--
309-- @since 0.1.2
316-- @since 0.1.2
310iterateM :: (IsStream t, MonadAsync m) => (a -> m a) -> a -> t m a
317iterateM :: (IsStream t, MonadAsync m) => (a -> m a) -> a -> t m a
src/Streamly/Tutorial.hs+16−11
@@ -40,9 +40,6 @@ module Streamly.Tutorial
40 -- * Flavors of Streams
40 -- * Flavors of Streams
41 -- $flavors
41 -- $flavors
42
42
43− -- * Writing Concurrent Programs
44− -- $programs
45−
46 -- * Imports and Supporting Code
43 -- * Imports and Supporting Code
47 -- $imports
44 -- $imports
48
45
@@ -129,6 +126,9 @@ module Streamly.Tutorial
129 -- * Reactive Programming
126 -- * Reactive Programming
130 -- $reactive
127 -- $reactive
131
128
129+ -- * Writing Concurrent Programs
130+ -- $programs
131+
132 -- * Performance
132 -- * Performance
133 -- $performance
133 -- $performance
134
134
@@ -238,14 +238,19 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
238--
238--
239-- When writing concurrent programs it is advised to not use the concurrent
239-- When writing concurrent programs it is advised to not use the concurrent
240-- style stream combinators blindly at the top level. That might create too
240-- style stream combinators blindly at the top level. That might create too
241−-- much concurrency where it is not even required and therefore degrade
241+-- much concurrency where it is not even required, and can even degrade
242+-- performance in some cases. In some cases it can also lead to surprising
243+-- behavior because of some code that is supposed to be serial becoming
242−-- performance. Please be aware of what all APIs that you have used may become
244+-- concurrent. Please be aware that all concurrency capable APIs that you may
243−-- concurrent when you use a concurrency combinator. For example if you have a
245+-- have used under the scope of a concurrent stream combinator will become
244−-- 'repeatM' somewhere in your program and you use 'parallely' on top, the
246+-- concurrent. For example if you have a 'repeatM' somewhere in your program
247+-- and you use 'parallely' on top, the 'repeatM' becomes fully parallel,
245−-- 'repeatM' becomes fully parallel, resulting into an infinite parallel
248+-- resulting into an infinite parallel execution . Instead, use the
246−-- execution . Instead start with a default serial program and add concurrent
249+-- /Keep It Serial and Stupid/ principle, start with the default serial
247−-- combinators where necessary, and use the 'serially' combinator to suppress
250+-- composition and enable concurrent combinators only when and where necessary.
251+-- When you use a concurrent combinator you can use an explicit 'serially'
248−-- unnecessary concurrency.
252+-- combinator to suppress any unnecessary concurrency under the scope of that
253+-- combinator.
249
254
250-- $monadtransformers
255-- $monadtransformers
251--
256--