@@ -47,21 +47,20 @@ module Streamly.Tutorial
4747 -- $transformation
4848
4949 -- * Merging Streams
50− -- $combining
5150
5251 -- ** Semigroup Style
5352 -- $semigroup
5453
55− -- *** Serial Composition ('streamly')
54+ -- *** Serial Depth First Composition ('Stream')
5655 -- $serial
5756
58− -- *** Serial Interleaved Composition ('costreamly')
57+ -- *** Serial Breadth First Composition ('Costream')
5958 -- $interleaved
6059
61− -- *** Left Biased Concurrent Composition ('coparallely')
62− -- $coparallel
60+ -- *** Concurrent Depth First Composition ('ParAhead')
61+ -- $parAhead
6362
64− -- *** Round Robin Concurrent Composition ('parallely')
63+ -- *** Concurrent Breadth First Composition ('CoParAhead')
6564 -- $parallel
6665
6766 -- *** Custom composition
@@ -76,16 +75,16 @@ module Streamly.Tutorial
7675 -- ** Monad
7776 -- $monad
7877
79− -- *** Serial Nesting ('streamly')
78+ -- *** Serial Depth First Nesting ('Stream')
8079 -- $regularSerial
8180
82− -- *** Serial Interleaved Nesting ('costreamly')
81+ -- *** Serial Breadth First Nesting ('Costream')
8382 -- $interleavedNesting
8483
85− -- *** Left Biased Concurrent Nesting ('coparallely')
84+ -- *** Concurrent Depth First Nesting ('ParAhead')
8685 -- $concurrentNesting
8786
88− -- *** Round Robin Concurrent Nesting ('parallely')
87+ -- *** Concurrent Breadth First Nesting ('CoparAhead')
8988 -- $fairlyConcurrentNesting
9089
9190 -- *** Exercise
@@ -156,7 +155,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
156155-- in fact a synonym for @StreamT IO@. There are a few more types similar to
157156-- 'StreamT' that all represent streams and differ only in the 'Semigroup',
158157-- 'Applicative' and 'Monad' compositions of the streams. 'Stream' and
159−-- 'Costream' types compose serially whereas 'Coparallel' and 'Parallel' types
158+-- 'Costream' types compose serially whereas 'ParAhead' and 'CoparAhead' types
160159-- compose concurrently. All these types can be freely inter-converted using
161160-- type combinators without any cost. You can freely switch to any type of
162161-- composition at any point in the program. When no type annotation or
@@ -190,7 +189,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
190189-- @StreamT IO@.
191190--
192191-- Similarly we have monad transformer types for other stream types as well viz.
193−-- 'CostreamT', 'CoparallelT' and 'ParallelT'.
192+-- 'CostreamT', 'ParAheadT' and 'CoparAheadT'.
194193--
195194-- To lift a value from an underlying monad in a monad transformer stack into a
196195-- singleton stream use 'lift' and to lift from an IO action use 'liftIO'.
@@ -309,13 +308,13 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
309308-- operation '<>'. Streams can be combined in many different ways as described
310309-- in the following sections, the '<>' operation behaves differently depending
311310-- on the stream type in effect. Streamly streams can be of many
312−-- different types i.e. 'Stream', 'Costream', 'Coparallel', 'Parallel',
311+-- different types i.e. 'Stream', 'Costream', 'ParAhead', 'CoparAhead',
313312-- 'ZipStream', and 'ZipParallel'. The first four are monads whereas the last
314313-- two are applicatives. These types can be freely converted from one to
315314-- another to acheive the desired composition style. To force a particular
316315-- type of composition we coerce the stream type using the corresponding type
317−-- adapting combinator from 'streamly', 'costreamly', 'coparallely',
318−-- 'parallely', 'zipStreamly' or 'zipParallely'. The default stream type is
316+-- adapting combinator from 'asStream', 'asCostream', 'asParAhead',
317+-- 'asCoparAhead', 'asZipStream' or 'asZipParallel'. The default stream type is
319318-- 'Stream' unless you change it by using one of the combinators.
320319--
321320-- To illustrate the concurrent vs serial composition aspects, we will use the
@@ -336,18 +335,20 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
336335-- $serial
337336--
338337-- The 'Semigroup' operation '<>' of the 'Stream' type combines the two streams
339−-- in a serial manner. We use the 'streamly' type combinator to effect 'Stream'
340−-- style of composition. We can also use the 'Stream' type annotation for the
341−-- stream type to acheive the same effect. However, since 'Stream' is the
342−-- default type unless explicitly specified by using a combinator, we can
343−-- omit using an explicit combinator or type annotation for this style of
344−-- composition.
338+-- in a /serial depth first/ manner. We use the 'asStream' type combinator to
339+-- effect 'Stream' style of composition. We can also use an explicit 'Stream'
340+-- type annotation for the stream to acheive the same effect. However, since
341+-- 'Stream' is the default type unless explicitly specified by using a
342+-- combinator, we can omit using an explicit combinator or type annotation for
343+-- this style of composition.
345344--
346345-- When two streams with multiple elements are combined in this manner, the
347346-- monadic actions in the two streams are performed sequentially i.e. first all
348347-- actions in the first stream are performed sequentially and then all actions
349−-- in the second stream are performed sequentially. The following example
350−-- prints the sequence 1, 2, 3, 4:
348+-- in the second stream are performed sequentially. We call it
349+-- /serial depth first/ as the full depth of one stream is fully traversed
350+-- before we move to the next. The following example prints the sequence 1, 2,
351+-- 3, 4:
351352--
352353-- @
353354-- main = 'runStream' $ (print 1 |: print 2 |: nil) <> (print 3 |: print 4 |: nil)
@@ -383,18 +384,18 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
383384-- $interleaved
384385--
385386-- The 'Semigroup' operation '<>' of the 'Costream' type combines the two
386−-- streams in a serial interleaved manner. We use the 'costreamly' type
387+-- streams in a /serial breadth first/ manner. We use the 'asCostream' type
387388-- combinator to effect 'Costream' style of composition. We can also use the
388−-- 'Costream' type annotation for the stream type to acheive the same effect.
389+-- 'Costream' type annotation for the stream to acheive the same effect.
389390--
390−-- When two streams with multiple elements are combined in this manner, the
391−-- monadic actions in the two streams are performed in an interleaved manner
392−-- i.e. one action from the first stream is performed and its output yielded
393−-- and then one action from the second stream is performed and its output
394−-- yielded, and so on. The following example prints the sequence 1, 3, 2, 4
391+-- When two streams with multiple elements are combined in this manner, we
392+-- traverse all the streams in a breadth first manner i.e. one action from each
393+-- stream is peformed and yielded to the resulting stream before we come back
394+-- to the first stream again and so on.
395+-- The following example prints the sequence 1, 3, 2, 4
395396--
396397-- @
397−-- main = 'runStream' . 'costreamly' $ (print 1 |: print 2 |: nil) <> (print 3 |: print 4 |: nil)
398+-- main = 'runStream' . 'asCostream' $ (print 1 |: print 2 |: nil) <> (print 3 |: print 4 |: nil)
398399-- @
399400-- @
400401-- 1
@@ -409,7 +410,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
409410-- thread and take a combined total of 6 seconds:
410411--
411412-- @
412−-- main = 'runStream' . 'costreamly' $ delay 3 <> delay 2 <> delay 1
413+-- main = 'runStream' . 'asCostream' $ delay 3 <> delay 2 <> delay 1
413414-- @
414415-- @
415416-- ThreadId 36: Delay 3
@@ -419,7 +420,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
419420--
420421-- The polymorphic version of the 'Costream' binary operation '<>' is called
421422-- 'cosplice'. We can use 'cosplice' to join streams in an interleaved manner
422−-- irrespective of the type, notice that we have not used the 'costreamly'
423+-- irrespective of the type, notice that we have not used the 'asCostream'
423424-- combinator in the following example:
424425--
425426-- @
@@ -435,28 +436,27 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
435436-- Note that this composition cannot be used to fold infinite number of streams
436437-- since it requires preserving the state until a stream is finished.
437438
438−-- $coparallel
439+-- $parAhead
439440--
440−-- The 'Semigroup' operation '<>' of the 'Coparallel' type combines the two
441−-- streams in a left biased concurrent manner. We use the 'coparallel' type
442−-- combinator to effect 'Coparallel' style of composition. We can also use the
443−-- 'Coparallel' type annotation for the stream type to acheive the same effect.
441+-- The 'Semigroup' operation '<>' of the 'ParAhead' type combines the two
442+-- streams in a depth first manner with parallel look ahead. We use the
443+-- 'asParAhead' type combinator to effect 'ParAhead' style of composition. We
444+-- can also use the 'ParAhead' type annotation for the stream type to acheive
445+-- the same effect.
444446--
445447-- When two streams with multiple elements are combined in this manner, the
446−-- monadic actions in the two streams can be performed concurrently
447−-- /when needed/ with a bias towards the left stream i.e. actions from the left
448−-- stream are performed sequentially, if the left stream blocks or cannot
449−-- generate enough output to keep the consumer of the stream busy then it can
450−-- execute actions from the right stream concurrently. The outputs of the
451−-- concurrent actions are yielded by the composite stream in the order in which
452−-- they complete. This can be thought of as the concurrent analogue of the
453−-- 'Stream' style serial composition. If concurrent execution is not trigerred
454−-- by consumer demand then it would execute actions exactly in the same order
455−-- as 'Stream'. In the following example the first stream does not block,
448+-- streams are traversed in depth first manner just like 'Stream', however it
449+-- can execute the next stream concurrently and return the results from it
450+-- as they arrive i.e. the results from the next stream may be yielded even
451+-- before the results from the first stream. Concurrent execution of the next
452+-- stream(s) is performed if the first stream blocks or if it cannot produce
453+-- output at the rate that is enough to meet the consumer demand. Multiple
454+-- streams can be executed concurrently to meet the demand.
455+-- In the following example the first stream does not block,
456456-- therefore the first stream is completely exhausted before the second.
457457--
458458-- @
459−-- main = 'runStream' . 'coparallely' $ (print 1 |: print 2 |: nil) <> (print 3 |: print 4 |: nil)
459+-- main = 'runStream' . 'asParAhead' $ (print 1 |: print 2 |: nil) <> (print 3 |: print 4 |: nil)
460460-- @
461461-- @
462462-- 1
@@ -470,7 +470,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
470470-- and 3 would be yielded first and then 2 and 4 would be yielded.
471471--
472472-- @
473−-- main = 'runStream' . 'coparallely' $ (p 1 |: p 2 |: nil) <> (p 3 |: p 4 |: nil)
473+-- main = 'runStream' . 'asParAhead' $ (p 1 |: p 2 |: nil) <> (p 3 |: p 4 |: nil)
474474-- where p n = threadDelay 1000000 >> print n
475475-- @
476476-- @
@@ -485,7 +485,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
485485-- shortest delay is printed first:
486486--
487487-- @
488−-- main = 'runStream' . 'coparallely' $ delay 3 '<>' delay 2 '<>' delay 1
488+-- main = 'runStream' . 'asParAhead' $ delay 3 '<>' delay 2 '<>' delay 1
489489-- @
490490-- @
491491-- ThreadId 42: Delay 1
@@ -504,7 +504,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
504504-- second as all of the actions are concurrent.
505505--
506506-- @
507−-- main = 'runStream' . 'coparallely' $ (delay 1 <> delay 2) <> (delay 3 <> delay 4)
507+-- main = 'runStream' . 'asParAhead' $ (delay 1 <> delay 2) <> (delay 3 <> delay 4)
508508-- @
509509-- @
510510-- 1
@@ -521,7 +521,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
521521-- even if none of them blocks:
522522--
523523-- @
524−-- main = 'runStream' . 'coparallely' $ traced (sqrt 9) '<>' traced (sqrt 16) '<>' traced (sqrt 25)
524+-- main = 'runStream' . 'asParAhead' $ traced (sqrt 9) '<>' traced (sqrt 16) '<>' traced (sqrt 25)
525525-- where traced m = S.'once' (myThreadId >>= print) >> return m
526526-- @
527527-- @
@@ -533,13 +533,13 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
533533-- Note that the order of printing in the above examples may change due to
534534-- variations in scheduling latencies for concurrent threads.
535535--
536−-- The polymorphic version of the 'Coparallel' binary operation '<>' is called
537−-- 'coparallel'. We can use 'coparallel' to join streams in a left biased
536+-- The polymorphic version of the 'ParAhead' binary operation '<>' is called
537+-- 'parAhead'. We can use 'parAhead' to join streams in a left biased
538538-- adaptively concurrent manner irrespective of the type, notice that we have
539−-- not used the 'coparallely' combinator in the following example:
539+-- not used the 'asParAhead' combinator in the following example:
540540--
541541-- @
542−-- main = 'runStream' $ delay 3 \`coparallel` delay 2 \`coparallel` delay 1
542+-- main = 'runStream' $ delay 3 \`parAhead` delay 2 \`parAhead` delay 1
543543-- @
544544-- @
545545-- ThreadId 42: Delay 1
@@ -555,12 +555,12 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
555555-- all computations at once for any reason 'Parallel' style must be used
556556-- instead.
557557--
558−-- 'Coparallel' style should be preferred over 'Parallel' unless you really
559−-- need 'Parallel'. It utilizes the resources optimally. It should be used when
558+-- 'ParAhead' style should be preferred over 'CoparAhead' unless you really
559+-- need 'CoparAhead'. It utilizes the resources optimally. It should be used when
560560-- we know that the computations can run in parallel but we do not care if they
561561-- actually run in parallel or not, that decision can be left to the scheduler
562562-- based on demand. Also, note that this operator can be used to fold infinite
563−-- number of streams in contrast to the 'Parallel' style, because it does not
563+-- number of streams in contrast to the 'CoparAhead' style, because it does not
564564-- require us to run all of them at the same time in a fair manner.
565565
566566-- $parallel
@@ -586,7 +586,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
586586-- import qualified Streamly.Prelude as S
587587-- import Network.HTTP.Simple
588588--
589−-- main = 'runStream' . 'parallely' $ google \<> bing \<> duckduckgo
589+-- main = 'runStream' . 'asParallel' $ google \<> bing \<> duckduckgo
590590-- where
591591-- google = get "https://www.google.com/search?q=haskell"
592592-- bing = get "https://www.bing.com/search?q=haskell"
@@ -594,12 +594,12 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
594594-- get s = S.'once' (httpNoBody (parseRequest_ s) >> putStrLn (show s))
595595-- @
596596--
597−-- In the following example we can see that the fairly parallel composition
597+-- In the following example we can see that the co-ahead parallel composition
598598-- yields outputs in the same order as the 'Costream' composition, though this
599599-- is not always guaranteed because of thread scheduling variances.
600600--
601601-- @
602−-- main = 'runStream' . 'parallely' $ (print 1 |: print 2 |: nil) <> (print 3 |: print 4 |: nil)
602+-- main = 'runStream' . 'asCoparAhead' $ (print 1 |: print 2 |: nil) <> (print 3 |: print 4 |: nil)
603603-- @
604604-- @
605605-- 1
@@ -608,13 +608,13 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
608608-- 4
609609-- @
610610--
611−-- The polymorphic version of the 'Parallel' binary operation '<>' is called
612−-- 'parallel'. We can use 'parallel' to join streams in a fairly
611+-- The polymorphic version of the 'CoparAhead' binary operation '<>' is called
612+-- 'coparAhead'. We can use 'coparAhead' to join streams in a fairly
613613-- concurrent manner irrespective of the type, notice that we have
614−-- not used the 'parallely' combinator in the following example:
614+-- not used the 'asCoparAhead' combinator in the following example:
615615--
616616-- @
617−-- main = 'runStream' $ delay 3 \`parallel` delay 2 \`parallel` delay 1
617+-- main = 'runStream' $ delay 3 \`coparAhead` delay 2 \`coparAhead` delay 1
618618-- @
619619-- @
620620-- ThreadId 42: Delay 1
@@ -635,7 +635,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
635635-- time. Take an example of a merge sort of two sorted streams. We need to
636636-- keep consuming items from the stream which has the lowest item in the sort
637637-- order. This can be achieved using async references to streams. See
638−-- "Streamly.Examples.MergeSortedStreams".
638+-- "MergeSort.hs" in the examples directory.
639639
640640-- $monoid
641641--
@@ -660,10 +660,10 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
660660-- import Control.Concurrent
661661--
662662-- main = do
663−-- 'runStream' $ 'parallely' $ foldMap delay [1..10]
664−-- 'runStream' $ 'foldWith' 'parallel' (map delay [1..10])
665−-- 'runStream' $ 'foldMapWith' 'parallel' delay [1..10]
666−-- 'runStream' $ 'forEachWith' 'parallel' [1..10] delay
663+-- 'runStream' $ 'asParAhead' $ foldMap delay [1..10]
664+-- 'runStream' $ 'foldWith' 'parAhead' (map delay [1..10])
665+-- 'runStream' $ 'foldMapWith' 'parAhead' delay [1..10]
666+-- 'runStream' $ 'forEachWith' 'parAhead' [1..10] delay
667667-- where delay n = S.'once' $ threadDelay (n * 1000000) >> print n
668668-- @
669669
@@ -688,7 +688,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
688688-- element in the first stream and for each element in the second stream
689689-- execute the body of the loop.
690690--
691−-- The 'Monad' instances of 'Stream', 'Costream', 'Coparallel' and 'Parallel'
691+-- The 'Monad' instances of 'Stream', 'Costream', 'ParAhead' and 'CoparAhead'
692692-- stream types support different flavors of nested looping. In other words,
693693-- they are all variants of list transformer. The nesting behavior of these
694694-- types exactly correspond to the way they merge streams as we discussed in
@@ -763,22 +763,22 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
763763
764764-- $concurrentNesting
765765--
766−-- The 'Monad' composition of 'Coparallel' type can perform the iterations of a
766+-- The 'Monad' composition of 'ParAhead' type can perform the iterations of a
767767-- loop concurrently. Concurrency is demand driven i.e. more concurrent
768768-- iterations are started only if the previous iterations are not able to
769769-- produce enough output for the consumer of the output stream. This works
770−-- exactly the same way as the merging of two streams 'coparallely' works.
770+-- exactly the same way as the merging of two streams 'asParAhead' works.
771771-- This is the concurrent analogue of 'Stream' style monadic composition.
772772--
773−-- The 'coparallely' type combinator can be used to switch to this
773+-- The 'asParAhead' type combinator can be used to switch to this
774774-- style of composition. Alternatively, a type annotation can be used to
775−-- specify the type of the stream as 'Coparallel'.
775+-- specify the type of the stream as 'ParAhead'.
776776--
777777-- @
778778-- import "Streamly"
779779-- import "Streamly.Prelude"
780780--
781−-- main = 'runStream' . 'coparallely' $ do
781+-- main = 'runStream' . 'asParAhead' $ do
782782-- x <- 'fromFoldable' [3,2,1]
783783-- delay x
784784-- @
@@ -794,7 +794,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
794794-- When compared to imperative programming, this can be viewed as a @for@ loop
795795-- with three concurrent iterations.
796796--
797−-- Concurrency is demand driven just as in the case of 'coparallel' merging.
797+-- Concurrency is demand driven just as in the case of 'parAhead' merging.
798798-- When multiple streams are composed using this style, the iterations are
799799-- triggered in a DFS manner just like 'Stream' i.e. nested iterations are
800800-- executed before we proceed to the next iteration at higher level. However,
@@ -805,7 +805,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
805805-- import "Streamly"
806806-- import qualified "Streamly.Prelude" as S
807807--
808−-- main = 'runStream' . 'coparallely' $ do
808+-- main = 'runStream' . 'asParAhead' $ do
809809-- x <- S.'fromFoldable' [1,2]
810810-- y <- S.'fromFoldable' [3,4]
811811-- S.'once' $ putStrLn $ show (x, y)
@@ -821,8 +821,8 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
821821--
822822-- The 'Monad' composition of 'Costream' type interleaves the iterations of
823823-- outer and inner loops in a nested loop composition. This works exactly the
824−-- same way as the merging of two streams in 'costreamly' fashion works. The
825−-- 'costreamly' type combinator can be used to switch to this style of
824+-- same way as the merging of two streams in 'asCostream' fashion works. The
825+-- 'asCostream' type combinator can be used to switch to this style of
826826-- composition. Alternatively, a type annotation can be used to specify the
827827-- type of the stream as 'Costream'.
828828--
@@ -830,7 +830,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
830830-- import "Streamly"
831831-- import qualified "Streamly.Prelude" as S
832832--
833−-- main = 'runStream' . 'costreamly' $ do
833+-- main = 'runStream' . 'asCostream' $ do
834834-- x <- S.'fromFoldable' [1,2]
835835-- y <- S.'fromFoldable' [3,4]
836836-- S.once $ putStrLn $ show (x, y)
@@ -846,7 +846,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
846846-- $fairlyConcurrentNesting
847847--
848848-- The 'Monad' composition of 'Parallel' type starts all the iterations of a
849−-- loop concurrently instead of demand driven as in the case of 'Coparallel'.
849+-- loop concurrently instead of demand driven as in the case of 'ParAhead'.
850850-- This works exactly the same way as the merging streams 'parallely' works.
851851-- The 'parallely' type combinator can be used to switch to this style of
852852-- composition. Alternatively, a type annotation can be used to specify the
@@ -894,10 +894,10 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
894894-- Now we can interpret this in whatever way we want:
895895--
896896-- @
897−-- main = 'runStream' . 'streamly' $ composed
898−-- main = 'runStream' . 'costreamly' $ composed
899−-- main = 'runStream' . 'coparallely' $ composed
900−-- main = 'runStream' . 'parallely' $ composed
897+-- main = 'runStream' . 'asStream' $ composed
898+-- main = 'runStream' . 'asCostream' $ composed
899+-- main = 'runStream' . 'asParAhead' $ composed
900+-- main = 'runStream' . 'asCoparAhead' $ composed
901901-- @
902902--
903903-- As an exercise try to figure out the output of this code for each mode of
@@ -937,7 +937,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
937937-- s2 = d 3 <> d 4
938938-- d n = delay n >> return n
939939--
940−-- main = (S.'toList' . 'streamly' $ (,) \<$> s1 \<*> s2) >>= print
940+-- main = (S.'toList' . 'asStream' $ (,) \<$> s1 \<*> s2) >>= print
941941-- @
942942-- @
943943-- ThreadId 36: Delay 1
@@ -953,7 +953,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
953953-- order but since it is serial it takes a total of 17 seconds:
954954--
955955-- @
956−-- main = (S.'toList' . 'costreamly' $ (,) \<$> s1 \<*> s2) >>= print
956+-- main = (S.'toList' . 'asCostream' $ (,) \<$> s1 \<*> s2) >>= print
957957-- @
958958-- @
959959-- ThreadId 36: Delay 1
@@ -965,11 +965,11 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
965965-- [(1,3),(2,3),(1,4),(2,4)]
966966-- @
967967--
968−-- 'Coparallel' can run the iterations concurrently and therefore takes a total
968+-- 'ParAhead' can run the iterations concurrently and therefore takes a total
969969-- of 10 seconds (1 + 2 + 3 + 4):
970970--
971971-- @
972−-- main = (S.'toList' . 'coparallely' $ (,) \<$> s1 \<*> s2) >>= print
972+-- main = (S.'toList' . 'asParAhead' $ (,) \<$> s1 \<*> s2) >>= print
973973-- @
974974-- @
975975-- ThreadId 34: Delay 1
@@ -981,11 +981,11 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
981981-- [(1,3),(2,3),(1,4),(2,4)]
982982-- @
983983--
984−-- Similalrly 'Parallel' as well can run the iterations concurrently and
984+-- Similalrly 'CoparAhead' as well can run the iterations concurrently and
985985-- therefore takes a total of 10 seconds (1 + 2 + 3 + 4):
986986--
987987-- @
988−-- main = (S.'toList' . 'parallely' $ (,) \<$> s1 \<*> s2) >>= print
988+-- main = (S.'toList' . 'asCoparAhead' $ (,) \<$> s1 \<*> s2) >>= print
989989-- @
990990-- @
991991-- ThreadId 34: Delay 1
@@ -999,21 +999,16 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
999999
10001000-- $compositionSummary
10011001--
1002−-- The following table summarizes the types for monadic compositions and the
1003−-- operators for sum style compositions. This table captures the essence of
1004−-- streamly.
1002+-- The following table summarizes the types for monadic and sum style
1003+-- compositions.
10051004--
10061005-- @
10071006-- +-----+--------------+--------------+
10081007-- | | Serial | Concurrent |
10091008-- +=====+==============+==============+
1010−-- | DFS | 'Stream' | 'Coparallel' |
1011−-- | +--------------+--------------+
1012−-- | | 'splice' | 'coparallel' |
1009+-- | DFS | 'Stream' | 'ParAhead' |
10131010-- +-----+--------------+--------------+
1014−-- | BFS | 'Costream' | 'Parallel' |
1015−-- | +--------------+--------------+
1016−-- | | 'cosplice' | 'parallel' |
1011+-- | BFS | 'Costream' | 'CoparAhead' |
10171012-- +-----+--------------+--------------+
10181013-- @
10191014
@@ -1029,7 +1024,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
10291024-- $serialzip
10301025--
10311026-- The applicative instance of 'ZipStream' type zips streams serially.
1032−-- 'zipStreamly' type combinator can be used to switch to serial applicative
1027+-- 'asZipStream' type combinator can be used to switch to serial applicative
10331028-- zip composition:
10341029--
10351030-- @
@@ -1041,7 +1036,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
10411036-- s1 = 'streamly' $ d 1 <> d 2
10421037-- s2 = 'streamly' $ d 3 <> d 4
10431038--
1044−-- main = (S.'toList' . 'zipStreamly' $ (,) \<$> s1 \<*> s2) >>= print
1039+-- main = (S.'toList' . 'asZipStream' $ (,) \<$> s1 \<*> s2) >>= print
10451040-- @
10461041--
10471042-- This takes total 10 seconds to zip, which is (1 + 2 + 3 + 4) since
@@ -1058,7 +1053,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
10581053-- $parallelzip
10591054--
10601055-- The applicative instance of 'ZipParallel' type zips streams concurrently.
1061−-- 'zipParallely' type combinator can be used to switch to parallel applicative
1056+-- 'asZipParallel' type combinator can be used to switch to parallel applicative
10621057-- zip composition:
10631058--
10641059--
@@ -1074,7 +1069,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
10741069--
10751070-- main = do
10761071-- hSetBuffering stdout LineBuffering
1077−-- (S.'toList' . 'zipParallely' $ (,) \<$> s1 \<*> s2) >>= print
1072+-- (S.'toList' . 'asZipParallel' $ (,) \<$> s1 \<*> s2) >>= print
10781073-- @
10791074--
10801075-- This takes 7 seconds to zip, which is max (1,3) + max (2,4) because 1 and 3
@@ -1098,11 +1093,11 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
10981093-- choose the desired type of concurrency.
10991094--
11001095-- In the following example the squares of @x@ and @y@ are computed
1101−-- concurrently using the 'coparallel' operation and the square roots of their
1096+-- concurrently using the 'parAhead' operation and the square roots of their
11021097-- sum are computed serially because of the 'streamly' combinator. We can
11031098-- choose different combinators for the monadic processing and the stream
1104−-- generation, to control the concurrency. We can also use the 'coparallely'
1105−-- combinator instead of explicitly folding with 'coparallel'.
1099+-- generation, to control the concurrency. We can also use the 'asParAhead'
1100+-- combinator instead of explicitly folding with 'parAhead'.
11061101--
11071102-- @
11081103-- import "Streamly"
@@ -1111,11 +1106,11 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
11111106--
11121107-- main = do
11131108-- z \<- S.'toList'
1114−-- $ 'streamly' -- Serial monadic processing (sqrt below)
1109+-- $ 'asStream' -- Serial monadic processing (sqrt below)
11151110-- $ do
1116−-- x2 \<- 'forEachWith' 'coparallel' [1..100] $ -- Concurrent @"for"@ loop
1111+-- x2 \<- 'forEachWith' 'parAhead' [1..100] $ -- Concurrent @"for"@ loop
11171112-- \\x -> return $ x * x -- body of the loop
1118−-- y2 \<- 'forEachWith' 'coparallel' [1..100] $
1113+-- y2 \<- 'forEachWith' 'parAhead' [1..100] $
11191114-- \\y -> return $ y * y
11201115-- return $ sqrt (x2 + y2)
11211116-- print $ sum z
@@ -1126,8 +1121,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
11261121-- and operators instead of the ugly pragmas.
11271122--
11281123-- For more concurrent programming examples see,
1129−-- "Streamly.Examples.ListDirRecursive", "Streamly.Examples.MergeSortedStreams"
1130−-- and "Streamly.Examples.SearchEngineQuery".
1124+-- "ListDir.hs", "MergeSort.hs" and "SearchQuery.hs" in the examples directory.
11311125
11321126-- $reactive
11331127--
@@ -1189,8 +1183,8 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
11891183-- return ()
11901184-- @
11911185--
1192−-- You can also find the source of this example in
1193−-- "Streamly.Examples.AcidRainGame". It has been adapted from Gabriel's
1186+-- You can also find the source of this example in the examples directory as
1187+-- "AcidRain.hs". It has been adapted from Gabriel's
11941188-- <https://hackage.haskell.org/package/pipes-concurrency-2.0.8/docs/Pipes-Concurrent-Tutorial.html pipes-concurrency>
11951189-- package.
11961190-- This is much simpler compared to the pipes version because of the builtin