on master help sign in
rename streams with a consistent and intuitive scheme

The trigger for this change is that parallel stream is not really parallel it is a concurrent lookahead like just in a different traversal style. So we make parallel and coparallel as parAhead and coparAhead instead and later introduce a new style for parallel which would be strictly parallel with one thread for each stream started right away rather than speculatively.

commit74dd5a01b6794013db689d07e8f762952d852a87 authorHarendra Kumar <harendra.kumar@gmail.com> dateMon 7 May 2018, 19:17 (8 years ago) parenta0b5ab2
12 files changed+534−525
Changelog.md+13−7 benchmark/Linear.hs+4−4 benchmark/Nested.hs+43−43 src/Streamly.hs+23−22 src/Streamly/Core.hs+12−12 src/Streamly/Streams.hs+131−123 src/Streamly/Tutorial.hs+111−117 test/Main.hs+91−91 test/Prop.hs+100−100 test/loops.hs+3−3 test/nested-loops.hs+1−1 test/parallel-loops.hs+2−2
Changelog.md+13−7
@@ -39,21 +39,24 @@
3939 * `MonadAsync` to `MonadParallel`
4040 * `Streaming` to `IsStream`
4141 * `runStreaming` to `runStream`
42− * `AsyncT` to `CoparallelT`
42+ * `InterleavedT` to `CostreamT`
43+ * `AsyncT` to `ParAheadT`
4344 * `ZipAsync` to `ZipParallelM`
44− * `interleaving` to `costreamly`
45− * `asyncly` to `coparallely`
46− * `zipping` to `zipStreamly`
47− * `zippingAsync` to `zipParallely`
45+ * `serially` to `asStream`
46+ * `interleaving` to `asCostream`
47+ * `asyncly` to `asParAhead`
48+ * `parallely` to `asParallel`
49+ * `zipping` to `asZipStream`
50+ * `zippingAsync` to `asZipParallel`
4851 * `<=>` to `cosplice`
49− * `<|` to `coparallel`
52+ * `<|` to `parAhead`
5053 * `each` to `fromFoldable`
5154 * `scan` to `scanx`
5255 * `foldl` to `foldx`
5356 * `foldlM` to `foldxM`
5457 * `zipAsyncWith` to `zipParallelWith`
5558 * `zipAsyncWithM` to `zipParallelWithM`
56−* Deprecate and remove the following symbols:
59+* Deprecate the following symbols for future removal:
5760 * `runStreamT`
5861 * `runInterleavedT`
5962 * `runAsyncT`
@@ -71,6 +74,9 @@
7174 * `foldlM'` strict left fold with a monadic fold function
7275 * `splice` run two streams serially one after the other
7376 * `parallel` run two streams in parallel (replaces `<|>`)
77+ * `CoparAhead` stream type for BFS version of ahead parallel composition
78+ * `coparAhead` ahead parallel composition of two streams
79+ * `asCoparAhead` type combinator for CoparAhead stream type
7480* Add simpler stream types that are specialized to the IO monad
7581
7682## 0.1.2
benchmark/Linear.hs+4−4
@@ -50,10 +50,10 @@ main = do
5050 ]
5151 , benchIO "zip" Ops.zip
5252 , bgroup "append"
53− [ benchIOAppend "streamly" $ Ops.append streamly
54− , benchIOAppend "costreamly" $ Ops.append costreamly
55− , benchIOAppend "coparallely" $ Ops.append coparallely
56− , benchIOAppend "parallely" $ Ops.append parallely
53+ [ benchIOAppend "asStream" $ Ops.append asStream
54+ , benchIOAppend "asCostream" $ Ops.append asCostream
55+ , benchIOAppend "asParAhead" $ Ops.append asParAhead
56+ , benchIOAppend "asCoparAhead" $ Ops.append asCoparAhead
5757 ]
5858 , bgroup "compose"
5959 [ benchIO "mapM" Ops.composeMapM
benchmark/Nested.hs+43−43
@@ -27,55 +27,55 @@ main = do
2727 , benchIO "toListLinear" Ops.toListLinear
2828 ]
2929
30− , bgroup "streamly"
31− [ benchIO "append" $ Ops.append streamly
32− , benchIO "toNull0" $ Ops.toNull0 streamly
33− , benchIO "toList0" $ Ops.toList0 streamly
34− , benchIO "toNull" $ Ops.toNull streamly
35− , benchIO "toList" $ Ops.toList streamly
36− , benchIO "toListSome" $ Ops.toListSome streamly
37− , benchIO "filterAllOut" $ Ops.filterAllOut streamly
38− , benchIO "filterAllIn" $ Ops.filterAllIn streamly
39− , benchIO "filterSome" $ Ops.filterSome streamly
40− , benchIO "breakAfterSome" $ Ops.breakAfterSome streamly
30+ , bgroup "asStream"
31+ [ benchIO "append" $ Ops.append asStream
32+ , benchIO "toNull0" $ Ops.toNull0 asStream
33+ , benchIO "toList0" $ Ops.toList0 asStream
34+ , benchIO "toNull" $ Ops.toNull asStream
35+ , benchIO "toList" $ Ops.toList asStream
36+ , benchIO "toListSome" $ Ops.toListSome asStream
37+ , benchIO "filterAllOut" $ Ops.filterAllOut asStream
38+ , benchIO "filterAllIn" $ Ops.filterAllIn asStream
39+ , benchIO "filterSome" $ Ops.filterSome asStream
40+ , benchIO "breakAfterSome" $ Ops.breakAfterSome asStream
4141 ]
4242
43− , bgroup "costreamly"
44− [ benchIO "append" $ Ops.append costreamly
45− , benchIO "toNull0" $ Ops.toNull0 costreamly
46− , benchIO "toList0" $ Ops.toList0 costreamly
47− , benchIO "toNull" $ Ops.toNull costreamly
48− , benchIO "toList" $ Ops.toList costreamly
49− , benchIO "toListSome" $ Ops.toListSome costreamly
50− , benchIO "filterAllOut" $ Ops.filterAllOut costreamly
51− , benchIO "filterAllIn" $ Ops.filterAllIn costreamly
52− , benchIO "filterSome" $ Ops.filterSome costreamly
53− , benchIO "breakAfterSome" $ Ops.breakAfterSome costreamly
43+ , bgroup "asCostream"
44+ [ benchIO "append" $ Ops.append asCostream
45+ , benchIO "toNull0" $ Ops.toNull0 asCostream
46+ , benchIO "toList0" $ Ops.toList0 asCostream
47+ , benchIO "toNull" $ Ops.toNull asCostream
48+ , benchIO "toList" $ Ops.toList asCostream
49+ , benchIO "toListSome" $ Ops.toListSome asCostream
50+ , benchIO "filterAllOut" $ Ops.filterAllOut asCostream
51+ , benchIO "filterAllIn" $ Ops.filterAllIn asCostream
52+ , benchIO "filterSome" $ Ops.filterSome asCostream
53+ , benchIO "breakAfterSome" $ Ops.breakAfterSome asCostream
5454 ]
5555
56− , bgroup "Coparallely"
57− [ benchIO "append" $ Ops.append coparallely
58− , benchIO "toNull0" $ Ops.toNull0 coparallely
59− , benchIO "toList0" $ Ops.toList0 coparallely
60− , benchIO "toNull" $ Ops.toNull coparallely
61− , benchIO "toList" $ Ops.toList coparallely
62− , benchIO "toListSome" $ Ops.toListSome coparallely
63− , benchIO "filterAllOut" $ Ops.filterAllOut coparallely
64− , benchIO "filterAllIn" $ Ops.filterAllIn coparallely
65− , benchIO "filterSome" $ Ops.filterSome coparallely
66− , benchIO "breakAfterSome" $ Ops.breakAfterSome coparallely
56+ , bgroup "CoasCoparAhead"
57+ [ benchIO "append" $ Ops.append asParAhead
58+ , benchIO "toNull0" $ Ops.toNull0 asParAhead
59+ , benchIO "toList0" $ Ops.toList0 asParAhead
60+ , benchIO "toNull" $ Ops.toNull asParAhead
61+ , benchIO "toList" $ Ops.toList asParAhead
62+ , benchIO "toListSome" $ Ops.toListSome asParAhead
63+ , benchIO "filterAllOut" $ Ops.filterAllOut asParAhead
64+ , benchIO "filterAllIn" $ Ops.filterAllIn asParAhead
65+ , benchIO "filterSome" $ Ops.filterSome asParAhead
66+ , benchIO "breakAfterSome" $ Ops.breakAfterSome asParAhead
6767 ]
6868
6969 , bgroup "Parallely"
70− [ benchIO "append" $ Ops.append parallely
71− , benchIO "toNull0" $ Ops.toNull0 parallely
72− , benchIO "toList0" $ Ops.toList0 parallely
73− , benchIO "toNull" $ Ops.toNull parallely
74− , benchIO "toList" $ Ops.toList parallely
75− , benchIO "toListSome" $ Ops.toListSome parallely
76− , benchIO "filterAllOut" $ Ops.filterAllOut parallely
77− , benchIO "filterAllIn" $ Ops.filterAllIn parallely
78− , benchIO "filterSome" $ Ops.filterSome parallely
79− , benchIO "breakAfterSome" $ Ops.breakAfterSome parallely
70+ [ benchIO "append" $ Ops.append asCoparAhead
71+ , benchIO "toNull0" $ Ops.toNull0 asCoparAhead
72+ , benchIO "toList0" $ Ops.toList0 asCoparAhead
73+ , benchIO "toNull" $ Ops.toNull asCoparAhead
74+ , benchIO "toList" $ Ops.toList asCoparAhead
75+ , benchIO "toListSome" $ Ops.toListSome asCoparAhead
76+ , benchIO "filterAllOut" $ Ops.filterAllOut asCoparAhead
77+ , benchIO "filterAllIn" $ Ops.filterAllIn asCoparAhead
78+ , benchIO "filterSome" $ Ops.filterSome asCoparAhead
79+ , benchIO "breakAfterSome" $ Ops.breakAfterSome asCoparAhead
8080 ]
8181 ]
src/Streamly.hs+23−22
@@ -21,7 +21,7 @@
2121-- in fact a synonym for @StreamT IO@. There are a few more types similar to
2222-- 'StreamT', all of them represent a stream and differ only in the
2323-- 'Semigroup', 'Applicative' and 'Monad' compositions of the stream. 'Stream'
24−-- and 'Costream' types compose serially whereas 'Coparallel' and 'Parallel'
24+-- and 'Costream' types compose serially whereas 'ParAhead' and 'CoparAhead'
2525-- types compose concurrently. All these types can be freely inter-converted
2626-- using type combinators without any cost. You can freely switch to any type
2727-- of composition at any point in the program. When no type annotation or
@@ -65,10 +65,10 @@ module Streamly
6565 , StreamT
6666 , CostreamT
6767
68− -- ** Parallel Streams
69− -- $parallel
70− , CoparallelT
71− , ParallelT
68+ -- ** Parallel Ahead Streams
69+ -- $parAhead
70+ , ParAheadT
71+ , CoparAheadT
7272
7373 -- ** Zipping Streams
7474 -- $zipping
@@ -79,26 +79,26 @@ module Streamly
7979 -- $sum
8080 , splice
8181 , cosplice
82− , coparallel
83− , parallel
82+ , parAhead
83+ , coparAhead
8484
8585 -- * Stream Type Adapters
8686 -- $adapters
8787 , IsStream
8888
89− , streamly
90− , costreamly
91− , coparallely
92− , parallely
93− , zipStreamly
94− , zipParallely
89+ , asStream
90+ , asCostream
91+ , asParAhead
92+ , asCoparAhead
93+ , asZipStream
94+ , asZipParallel
9595 , adapt
9696
9797 -- * IO Streams
9898 , Stream
9999 , Costream
100− , Coparallel
101− , Parallel
100+ , ParAhead
101+ , CoparAhead
102102 , ZipStream
103103 , ZipParallel
104104
@@ -132,6 +132,7 @@ module Streamly
132132 , serially
133133 , interleaving
134134 , asyncly
135+ , parallely
135136 , zipping
136137 , zippingAsync
137138 , (<=>)
@@ -151,12 +152,12 @@ import Data.Semigroup (Semigroup(..))
151152-- streams are serial, the sequence of items in a composed stream can be solely
152153-- determined by the position of elements in the consituent streams.
153154
154−-- $parallel
155+-- $parAhead
155156--
156−-- Parallel streams compose parallely or concurrently. In a composed stream, at
157+-- Parallel ahead streams compose in an ahead parallel manner. In a composed stream, at
157158-- any point of time more than one stream can run concurrently and yield
158−-- elements. The two parallel types 'ParallelT' and 'CoparallelT' differ in how
159−-- they merge streams together in a 'Semigroup' or 'Monad' composition. As
159+-- elements. The two parallel ahead types 'ParAheadT' and 'coParAheadT' differ in how
160+-- they merge streams together in 'Semigroup' or 'Monad' compositions. As
160161-- these streams compose concurrently, the sequence of items in a composed
161162-- stream cannot be determined by the position of elements in the constituent
162163-- streams. The elements are yielded by the composed stream as they are
@@ -184,10 +185,10 @@ import Data.Semigroup (Semigroup(..))
184185-- one stream type to another. It is not used directly, instead the type
185186-- combinators provided below are used for conversions.
186187--
187−-- To adapt from one monomorphic type (e.g. 'ParallelT') to another monomorphic
188+-- To adapt from one monomorphic type (e.g. 'parAheadT') to another monomorphic
188189-- type (e.g. 'StreamT') use the 'adapt' combinator. To give a polymorphic code
189190-- a specific interpretation or to adapt a specific type to a polymorphic type
190−-- use the type specific combinators e.g. 'parallely' or 'costreamly'. You
191+-- use the type specific combinators e.g. 'asParAhead' or 'asCostream'. You
191192-- cannot adapt polymorphic code to polymorphic code, as it would not know
192193-- which specific type you are converting from or to. If you see a an
193194-- @ambiguous type variable@ error then most likely you are using 'adapt'
@@ -197,5 +198,5 @@ import Data.Semigroup (Semigroup(..))
197198-- $foldutils
198199--
199200-- These are variants of standard 'Foldable' fold functions that use a
200−-- polymorphic stream sum operation (e.g. 'parallel' or 'cosplice') to fold a
201+-- polymorphic stream sum operation (e.g. 'parAhead' or 'cosplice') to fold a
201202-- container of streams.
src/Streamly/Core.hs+12−12
@@ -35,8 +35,8 @@ module Streamly.Core
3535 -- * Semigroup Style Composition
3636 , splice
3737 , cosplice
38− , coparallel
39− , parallel
38+ , parAhead
39+ , coparAhead
4040
4141 -- * Alternative
4242 , alt
@@ -521,8 +521,8 @@ toStreamVar sv m = do
521521--
522522-- TBD Note 2: We may want to run computations at the lower level of the
523523-- composition tree serially even when they are composed using a parallel
524−-- combinator. We can use 'splice' in place of 'coparallel' and 'cosplice' in
525−-- place of 'parallel'. If we find that an SVar immediately above a computation
524+-- combinator. We can use 'splice' in place of 'parAhead' and 'cosplice' in
525+-- place of 'coParAhead'. If we find that an SVar immediately above a computation
526526-- gets drained empty we can switch to parallelizing the computation. For that
527527-- we can use a state flag to fork the rest of the computation at any point of
528528-- time inside the Monad bind operation if the consumer is running at a faster
@@ -564,9 +564,9 @@ withNewSVar2 style m1 m2 = Stream $ \_ stp sng yld -> do
564564-- Cases when we need to switch to a new SVar:
565565--
566566-- * (x `parallel` y) `parallel` (t `parallel` u) -- all of them get scheduled on the same SVar
567−-- * (x `parallel` y) `parallel` (t `coparallel` u) -- @t@ and @u@ get scheduled on a new child SVar
567+-- * (x `parallel` y) `parallel` (t `parAhead` u) -- @t@ and @u@ get scheduled on a new child SVar
568568-- because of the scheduling policy change.
569−-- * if we 'adapt' a stream of type 'Coparallel' to a stream of type
569+-- * if we 'adapt' a stream of type 'parAhead' to a stream of type
570570-- 'Parallel', we create a new SVar at the transitioning bind.
571571-- * When the stream is switching from disjunctive composition to conjunctive
572572-- composition and vice-versa we create a new SVar to isolate the scheduling
@@ -585,13 +585,13 @@ joinStreamVar2 style m1 m2 = Stream $ \svr stp sng yld ->
585585-- Semigroup and Monoid style compositions for parallel actions
586586------------------------------------------------------------------------------
587587
588−{-# INLINE coparallel #-}
589−coparallel :: MonadParallel m => Stream m a -> Stream m a -> Stream m a
590−coparallel = joinStreamVar2 (SVarStyle Disjunction LIFO)
588+{-# INLINE parAhead #-}
589+parAhead :: MonadParallel m => Stream m a -> Stream m a -> Stream m a
590+parAhead = joinStreamVar2 (SVarStyle Disjunction LIFO)
591591
592−{-# INLINE parallel #-}
593−parallel :: MonadParallel m => Stream m a -> Stream m a -> Stream m a
594−parallel = joinStreamVar2 (SVarStyle Disjunction FIFO)
592+{-# INLINE coparAhead #-}
593+coparAhead :: MonadParallel m => Stream m a -> Stream m a -> Stream m a
594+coparAhead = joinStreamVar2 (SVarStyle Disjunction FIFO)
595595
596596-------------------------------------------------------------------------------
597597-- Functor instace is the same for all types
src/Streamly/Streams.hs+131−123
@@ -54,16 +54,16 @@ module Streamly.Streams
5454 -- * Merging Streams
5555 , splice
5656 , cosplice
57− , coparallel
58− , parallel
57+ , parAhead
58+ , coparAhead
5959 , (<=>) --deprecated
6060 , (<|) --deprecated
6161
6262 -- * IO Streams
6363 , Stream
6464 , Costream
65− , Coparallel
66− , Parallel
65+ , ParAhead
66+ , CoparAhead
6767 , ZipStream
6868 , ZipParallel
6969
@@ -71,24 +71,25 @@ module Streamly.Streams
7171 , StreamT
7272 , CostreamT
7373 , InterleavedT -- deprecated
74− , CoparallelT
74+ , ParAheadT
7575 , AsyncT -- deprecated
76− , ParallelT
76+ , CoparAheadT
7777 , ZipStreamM
7878 , ZipParallelM
7979 , ZipAsync -- deprecated
8080
8181 -- * Type Adapters
82− , streamly
82+ , asStream
8383 , serially -- deprecated
84− , costreamly
84+ , asCostream
8585 , interleaving -- deprecated
86− , coparallely
86+ , asParAhead
8787 , asyncly -- deprecated
88− , parallely
89− , zipStreamly
88+ , asCoparAhead
89+ , parallely -- deprecated
90+ , asZipStream
9091 , zipping -- deprecated
91− , zipParallely
92+ , asZipParallel
9293 , zippingAsync -- deprecated
9394 , adapt
9495
@@ -257,7 +258,7 @@ streamFold svr step single blank m =
257258
258259-- | Run a streaming composition, discard the results. By default it interprets
259260-- the stream as 'StreamT', to run other types of streams use the type adapting
260−-- combinators for example @runStream . 'parallely'@.
261+-- combinators for example @runStream . 'asParAhead'@.
261262--
262263-- @since 0.2.0
263264runStream :: Monad m => StreamT m a -> m ()
@@ -347,17 +348,17 @@ instance (MonadState s m CONSTRAINT) => MonadState s (STREAM m) where { \
347348-- second stream.
348349--
349350-- @
350−-- main = ('toList' . 'streamly' $ (fromFoldable [1,2]) \<\> (fromFoldable [3,4])) >>= print
351+-- main = ('toList' . 'asStream' $ (fromFoldable [1,2]) \<\> (fromFoldable [3,4])) >>= print
351352-- @
352353-- @
353354-- [1,2,3,4]
354355-- @
355356--
356357-- The 'Monad' instance runs the /monadic continuation/ for each
357−-- element of the stream, streamly.
358+-- element of the stream, asStream.
358359--
359360-- @
360−-- main = 'runStream' . 'streamly' $ do
361+-- main = 'runStream' . 'asStream' $ do
361362-- x <- return 1 \<\> return 2
362363-- liftIO $ print x
363364-- @
@@ -366,10 +367,10 @@ instance (MonadState s m CONSTRAINT) => MonadState s (STREAM m) where { \
366367-- 2
367368-- @
368369--
369−-- 'StreamT' nests streams streamly in a depth first manner.
370+-- 'StreamT' nests streams serially in a depth first manner.
370371--
371372-- @
372−-- main = 'runStream' . 'streamly' $ do
373+-- main = 'runStream' . 'asStream' $ do
373374-- x <- return 1 \<\> return 2
374375-- y <- return 3 \<\> return 4
375376-- liftIO $ print (x, y)
@@ -387,7 +388,7 @@ instance (MonadState s m CONSTRAINT) => MonadState s (STREAM m) where { \
387388-- nested @for@ loops and the monadic continuation is the body of the loop. The
388389-- loop iterates for all elements of the stream.
389390--
390−-- The 'streamly' combinator can be omitted as the default stream type is
391+-- The 'asStream' combinator can be omitted as the default stream type is
391392-- 'StreamT'.
392393-- Note that serial composition can be used to combine an infinite number of
393394-- streams as it explores only one stream at a time.
@@ -440,7 +441,7 @@ MONAD_COMMON_INSTANCES(StreamT,)
440441-- yielding one element from each stream alternately.
441442--
442443-- @
443−-- main = ('toList' . 'costreamly' $ (fromFoldable [1,2]) \<\> (fromFoldable [3,4])) >>= print
444+-- main = ('toList' . 'asCostream' $ (fromFoldable [1,2]) \<\> (fromFoldable [3,4])) >>= print
444445-- @
445446-- @
446447-- [1,3,2,4]
@@ -451,7 +452,7 @@ MONAD_COMMON_INSTANCES(StreamT,)
451452--
452453--
453454-- @
454−-- main = 'runStream' . 'costreamly' $ do
455+-- main = 'runStream' . 'asCostream' $ do
455456-- x <- return 1 \<\> return 2
456457-- y <- return 3 \<\> return 4
457458-- liftIO $ print (x, y)
@@ -463,7 +464,7 @@ MONAD_COMMON_INSTANCES(StreamT,)
463464-- (2,4)
464465-- @
465466--
466−-- Note that costreamly composition can only combine a finite number of
467+-- Note that a 'Costream' composition can only combine a finite number of
467468-- streams as it needs to retain state for each unfinished stream.
468469--
469470-- @since 0.2.0
@@ -532,17 +533,17 @@ MONAD_APPLICATIVE_INSTANCE(CostreamT,)
532533MONAD_COMMON_INSTANCES(CostreamT,)
533534
534535------------------------------------------------------------------------------
535−-- CoparallelT
536+-- ParAheadT
536537------------------------------------------------------------------------------
537538
538−-- | Adaptive parallel, in a left to right 'Semigroup' composition it tries to
539+-- | Adaptive ahead parallel, in a left to right 'Semigroup' composition it tries to
539540-- yield elements from the left stream as long as it can, but it can run the
540541-- right stream in parallel if it needs to, based on demand. The right stream
541542-- can be run if the left stream blocks on IO or cannot produce elements fast
542543-- enough for the consumer.
543544--
544545-- @
545−-- main = ('toList' . 'coparallely' $ (fromFoldable [1,2]) \<> (fromFoldable [3,4])) >>= print
546+-- main = ('toList' . 'asParAhead' $ (fromFoldable [1,2]) \<> (fromFoldable [3,4])) >>= print
546547-- @
547548-- @
548549-- [1,2,3,4]
@@ -555,7 +556,7 @@ MONAD_COMMON_INSTANCES(CostreamT,)
555556-- different streams in the resulting stream can vary depending on scheduling
556557-- and generation delays.
557558--
558−-- Similarly, the monad instance of 'ParallelT' /may/ run each iteration
559+-- Similarly, the monad instance of 'CoparAheadT' /may/ run each iteration
559560-- concurrently based on demand. More concurrent iterations are started only
560561-- if the previous iterations are not able to produce enough output for the
561562-- consumer.
@@ -564,7 +565,7 @@ MONAD_COMMON_INSTANCES(CostreamT,)
564565-- import "Streamly"
565566-- import Control.Concurrent
566567--
567−-- main = 'runStream' . 'coparallely' $ do
568+-- main = 'runStream' . 'asParAhead' $ do
568569-- n <- return 3 \<\> return 2 \<\> return 1
569570-- liftIO $ do
570571-- threadDelay (n * 1000000)
@@ -582,47 +583,47 @@ MONAD_COMMON_INSTANCES(CostreamT,)
582583-- as it explores only a bounded number of streams at a time.
583584--
584585-- @since 0.2.0
585−newtype CoparallelT m a = CoparallelT {getCoparallelT :: S.Stream m a}
586+newtype ParAheadT m a = ParAheadT {getParAheadT :: S.Stream m a}
586587 deriving (Functor, MonadTrans)
587588
588589-- |
589590-- @since 0.1.0
590−{-# DEPRECATED AsyncT "Please use 'CoparallelT' instead." #-}
591−type AsyncT = CoparallelT
591+{-# DEPRECATED AsyncT "Please use 'ParAheadT' instead." #-}
592+type AsyncT = ParAheadT
592593
593−instance IsStream CoparallelT where
594− toStream = getCoparallelT
595− fromStream = CoparallelT
594+instance IsStream ParAheadT where
595+ toStream = getParAheadT
596+ fromStream = ParAheadT
596597
597598------------------------------------------------------------------------------
598599-- Semigroup
599600------------------------------------------------------------------------------
600601
601−-- | Polymorphic version of the 'Semigroup' operation '<>' of 'CoparallelT'.
602+-- | Polymorphic version of the 'Semigroup' operation '<>' of 'ParAheadT'.
602603-- Merges two streams possibly concurrently, preferring the
603604-- elements from the left one when available.
604605--
605606-- @since 0.2.0
606−{-# INLINE coparallel #-}
607−coparallel :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
608−coparallel m1 m2 = fromStream $ S.coparallel (toStream m1) (toStream m2)
607+{-# INLINE parAhead #-}
608+parAhead :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
609+parAhead m1 m2 = fromStream $ S.parAhead (toStream m1) (toStream m2)
609610
610−instance MonadParallel m => Semigroup (CoparallelT m a) where
611− (<>) = coparallel
611+instance MonadParallel m => Semigroup (ParAheadT m a) where
612+ (<>) = parAhead
612613
613−-- | Same as 'coparallel'.
614+-- | Same as 'parAhead'.
614615--
615616-- @since 0.1.0
616−{-# DEPRECATED (<|) "Please use 'coparallel' instead." #-}
617+{-# DEPRECATED (<|) "Please use 'parAhead' instead." #-}
617618{-# INLINE (<|) #-}
618619(<|) :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
619−(<|) = coparallel
620+(<|) = parAhead
620621
621622------------------------------------------------------------------------------
622623-- Monoid
623624------------------------------------------------------------------------------
624625
625−instance MonadParallel m => Monoid (CoparallelT m a) where
626+instance MonadParallel m => Monoid (ParAheadT m a) where
626627 mempty = nil
627628 mappend = (<>)
628629
@@ -645,29 +646,29 @@ parbind par m f = go m
645646 yield a r = run $ f a `par` go r
646647 in g Nothing stp single yield
647648
648−instance MonadParallel m => Monad (CoparallelT m) where
649+instance MonadParallel m => Monad (ParAheadT m) where
649650 return = pure
650− (CoparallelT m) >>= f = CoparallelT $ parbind par m (getCoparallelT . f)
651+ (ParAheadT m) >>= f = ParAheadT $ parbind par m (getParAheadT . f)
651652 where par = S.joinStreamVar2 (SVarStyle Conjunction LIFO)
652653
653654------------------------------------------------------------------------------
654655-- Other instances
655656------------------------------------------------------------------------------
656657
657−MONAD_APPLICATIVE_INSTANCE(CoparallelT,MONADPARALLEL)
658−MONAD_COMMON_INSTANCES(CoparallelT, MONADPARALLEL)
658+MONAD_APPLICATIVE_INSTANCE(ParAheadT,MONADPARALLEL)
659+MONAD_COMMON_INSTANCES(ParAheadT, MONADPARALLEL)
659660
660661------------------------------------------------------------------------------
661−-- ParallelT
662+-- CoparAheadT
662663------------------------------------------------------------------------------
663664
664665-- | Round robin concurrent composition.
665666--
666−-- The Semigroup instance of 'ParallelT' concurrently /merges/ streams in a
667+-- The Semigroup instance of 'CoparAheadT' concurrently /merges/ streams in a
667668-- round robin fashion, yielding elements from both streams alternately.
668669--
669670-- @
670−-- main = ('toList' . 'parallely' $ (fromFoldable [1,2]) \<> (fromFoldable [3,4])) >>= print
671+-- main = ('toList' . 'asCoparAhead' $ (fromFoldable [1,2]) \<> (fromFoldable [3,4])) >>= print
671672-- @
672673-- @
673674-- [1,3,2,4]
@@ -680,14 +681,14 @@ MONAD_COMMON_INSTANCES(CoparallelT, MONADPARALLEL)
680681-- different streams in the resulting stream can vary depending on scheduling
681682-- and generation delays.
682683--
683−-- Similarly, the 'Monad' instance of 'ParallelT' runs /all/ iterations fairly
684+-- Similarly, the 'Monad' instance of 'CoparAheadT' runs /all/ iterations fairly
684685-- concurrently using a round robin scheduling.
685686--
686687-- @
687688-- import "Streamly"
688689-- import Control.Concurrent
689690--
690−-- main = 'runStream' . 'parallely' $ do
691+-- main = 'runStream' . 'asCoparAhead' $ do
691692-- n <- return 3 \<\> return 2 \<\> return 1
692693-- liftIO $ do
693694-- threadDelay (n * 1000000)
@@ -699,40 +700,40 @@ MONAD_COMMON_INSTANCES(CoparallelT, MONADPARALLEL)
699700-- ThreadId 38: Delay 3
700701-- @
701702--
702−-- Unlike 'CoparallelT' all iterations are guaranteed to run fairly
703+-- Unlike 'ParAheadT' all iterations are guaranteed to run fairly
703704-- concurrently, unconditionally.
704705--
705706-- Note that round robin composition can only combine a finite number of
706707-- streams as it needs to retain state for each unfinished stream.
707708--
708709-- @since 0.1.0
709−newtype ParallelT m a = ParallelT {getParallelT :: S.Stream m a}
710+newtype CoparAheadT m a = CoparAheadT {getCoparAheadT :: S.Stream m a}
710711 deriving (Functor, MonadTrans)
711712
712−instance IsStream ParallelT where
713− toStream = getParallelT
714− fromStream = ParallelT
713+instance IsStream CoparAheadT where
714+ toStream = getCoparAheadT
715+ fromStream = CoparAheadT
715716
716717------------------------------------------------------------------------------
717718-- Semigroup
718719------------------------------------------------------------------------------
719720
720−-- | Polymorphic version of the 'Semigroup' operation '<>' of 'ParallelT'.
721+-- | Polymorphic version of the 'Semigroup' operation '<>' of 'CoparAheadT'.
721722-- Merges two streams concurrently choosing elements from both fairly.
722723--
723724-- @since 0.2.0
724−{-# INLINE parallel #-}
725−parallel :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
726−parallel m1 m2 = fromStream $ S.parallel (toStream m1) (toStream m2)
725+{-# INLINE coparAhead #-}
726+coparAhead :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
727+coparAhead m1 m2 = fromStream $ S.coparAhead (toStream m1) (toStream m2)
727728
728−instance MonadParallel m => Semigroup (ParallelT m a) where
729− (<>) = parallel
729+instance MonadParallel m => Semigroup (CoparAheadT m a) where
730+ (<>) = coparAhead
730731
731732------------------------------------------------------------------------------
732733-- Monoid
733734------------------------------------------------------------------------------
734735
735−instance MonadParallel m => Monoid (ParallelT m a) where
736+instance MonadParallel m => Monoid (CoparAheadT m a) where
736737 mempty = nil
737738 mappend = (<>)
738739
@@ -740,17 +741,17 @@ instance MonadParallel m => Monoid (ParallelT m a) where
740741-- Monad
741742------------------------------------------------------------------------------
742743
743−instance MonadParallel m => Monad (ParallelT m) where
744+instance MonadParallel m => Monad (CoparAheadT m) where
744745 return = pure
745− (ParallelT m) >>= f = ParallelT $ parbind par m (getParallelT . f)
746+ (CoparAheadT m) >>= f = CoparAheadT $ parbind par m (getCoparAheadT . f)
746747 where par = S.joinStreamVar2 (SVarStyle Conjunction FIFO)
747748
748749------------------------------------------------------------------------------
749750-- Other instances
750751------------------------------------------------------------------------------
751752
752−MONAD_APPLICATIVE_INSTANCE(ParallelT,MONADPARALLEL)
753−MONAD_COMMON_INSTANCES(ParallelT, MONADPARALLEL)
753+MONAD_APPLICATIVE_INSTANCE(CoparAheadT,MONADPARALLEL)
754+MONAD_COMMON_INSTANCES(CoparAheadT, MONADPARALLEL)
754755
755756------------------------------------------------------------------------------
756757-- Serially Zipping Streams
@@ -761,7 +762,7 @@ MONAD_COMMON_INSTANCES(ParallelT, MONADPARALLEL)
761762-- those elements.
762763--
763764-- @
764−-- main = (toList . 'zipStreamly' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
765+-- main = (toList . 'asZipStream' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
765766-- where s1 = fromFoldable [1, 2]
766767-- s2 = fromFoldable [3, 4]
767768-- s3 = fromFoldable [5, 6]
@@ -793,7 +794,7 @@ instance Monad m => Applicative (ZipStreamM m) where
793794-- be zipped concurrently.
794795--
795796-- @
796−-- main = (toList . 'zipParallely' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
797+-- main = (toList . 'asZipParallel' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
797798-- where s1 = fromFoldable [1, 2]
798799-- s2 = fromFoldable [3, 4]
799800-- s3 = fromFoldable [5, 6]
@@ -835,73 +836,80 @@ adapt = fromStream . toStream
835836-- | Fix the type of a polymorphic stream as 'StreamT'.
836837--
837838-- @since 0.2.0
838−streamly :: IsStream t => StreamT m a -> t m a
839−streamly = adapt
839+asStream :: IsStream t => StreamT m a -> t m a
840+asStream = adapt
840841
841−-- | Same as 'streamly'.
842+-- | Same as 'asStream'.
842843--
843844-- @since 0.1.0
844−{-# DEPRECATED serially "Please use streamly instead." #-}
845+{-# DEPRECATED serially "Please use asStream instead." #-}
845846serially :: IsStream t => StreamT m a -> t m a
846−serially = streamly
847+serially = asStream
847848
848849-- | Fix the type of a polymorphic stream as 'CostreamT'.
849850--
850851-- @since 0.2.0
851−costreamly :: IsStream t => CostreamT m a -> t m a
852−costreamly = adapt
852+asCostream :: IsStream t => CostreamT m a -> t m a
853+asCostream = adapt
853854
854−-- | Same as 'costreamly'.
855+-- | Same as 'asCostream'.
855856--
856857-- @since 0.1.0
857−{-# DEPRECATED interleaving "Please use costreamly instead." #-}
858+{-# DEPRECATED interleaving "Please use asCostream instead." #-}
858859interleaving :: IsStream t => CostreamT m a -> t m a
859−interleaving = costreamly
860+interleaving = asCostream
860861
861−-- | Fix the type of a polymorphic stream as 'CoparallelT'.
862+-- | Fix the type of a polymorphic stream as 'ParAheadT'.
862863--
863864-- @since 0.2.0
864−coparallely :: IsStream t => CoparallelT m a -> t m a
865−coparallely = adapt
865+asParAhead :: IsStream t => ParAheadT m a -> t m a
866+asParAhead = adapt
866867
867−-- | Same as 'coparallely'.
868+-- | Same as 'asParAhead'.
868869--
869870-- @since 0.1.0
870−{-# DEPRECATED asyncly "Please use coparallely instead." #-}
871−asyncly :: IsStream t => CoparallelT m a -> t m a
872−asyncly = coparallely
871+{-# DEPRECATED asyncly "Please use asParAhead instead." #-}
872+asyncly :: IsStream t => ParAheadT m a -> t m a
873+asyncly = asParAhead
873874
874−-- | Fix the type of a polymorphic stream as 'ParallelT'.
875+-- | Fix the type of a polymorphic stream as 'CoparAheadT'.
875876--
876877-- @since 0.1.0
877−parallely :: IsStream t => ParallelT m a -> t m a
878−parallely = adapt
878+asCoparAhead :: IsStream t => CoparAheadT m a -> t m a
879+asCoparAhead = adapt
880+
881+-- | Same as 'asCoparAhead'.
882+--
883+-- @since 0.1.0
884+{-# DEPRECATED parallely "Please use asCoparAhead instead." #-}
885+parallely :: IsStream t => CoparAheadT m a -> t m a
886+parallely = asCoparAhead
879887
880888-- | Fix the type of a polymorphic stream as 'ZipStreamM'.
881889--
882890-- @since 0.2.0
883−zipStreamly :: IsStream t => ZipStreamM m a -> t m a
884−zipStreamly = adapt
891+asZipStream :: IsStream t => ZipStreamM m a -> t m a
892+asZipStream = adapt
885893
886−-- | Same as 'zipStreamly'.
894+-- | Same as 'asZipStream'.
887895--
888896-- @since 0.1.0
889−{-# DEPRECATED zipping "Please use zipStreamly instead." #-}
897+{-# DEPRECATED zipping "Please use asZipStream instead." #-}
890898zipping :: IsStream t => ZipStreamM m a -> t m a
891−zipping = zipStreamly
899+zipping = asZipStream
892900
893901-- | Fix the type of a polymorphic stream as 'ZipParallelM'.
894902--
895903-- @since 0.2.0
896−zipParallely :: IsStream t => ZipParallelM m a -> t m a
897−zipParallely = adapt
904+asZipParallel :: IsStream t => ZipParallelM m a -> t m a
905+asZipParallel = adapt
898906
899−-- | Same as 'zipParallely'.
907+-- | Same as 'asZipParallel'.
900908--
901909-- @since 0.1.0
902−{-# DEPRECATED zippingAsync "Please use zipParallely instead." #-}
910+{-# DEPRECATED zippingAsync "Please use asZipParallel instead." #-}
903911zippingAsync :: IsStream t => ZipParallelM m a -> t m a
904−zippingAsync = zipParallely
912+zippingAsync = asZipParallel
905913
906914-------------------------------------------------------------------------------
907915-- Running Streams, convenience functions specialized to types
@@ -914,40 +922,40 @@ zippingAsync = zipParallely
914922runStreamT :: Monad m => StreamT m a -> m ()
915923runStreamT = runStream
916924
917−-- | Same as @runStream . costreamly@.
925+-- | Same as @runStream . asCostream@.
918926--
919927-- @since 0.1.0
920928{-# DEPRECATED runInterleavedT "Please use 'runStream . interleaving' instead." #-}
921929runInterleavedT :: Monad m => InterleavedT m a -> m ()
922−runInterleavedT = runStream . costreamly
930+runInterleavedT = runStream . asCostream
923931
924−-- | Same as @runStream . coparallely@.
932+-- | Same as @runStream . asParAhead@.
925933--
926934-- @since 0.1.0
927−{-# DEPRECATED runAsyncT "Please use 'runStream . coparallely' instead." #-}
928−runAsyncT :: Monad m => CoparallelT m a -> m ()
929−runAsyncT = runStream . coparallely
935+{-# DEPRECATED runAsyncT "Please use 'runStream . asParAhead' instead." #-}
936+runAsyncT :: Monad m => ParAheadT m a -> m ()
937+runAsyncT = runStream . asParAhead
930938
931−-- | Same as @runStream . parallely@.
939+-- | Same as @runStream . asCoparAhead@.
932940--
933941-- @since 0.1.0
934−{-# DEPRECATED runParallelT "Please use 'runStream . parallely' instead." #-}
935−runParallelT :: Monad m => ParallelT m a -> m ()
936−runParallelT = runStream . parallely
942+{-# DEPRECATED runParallelT "Please use 'runStream . asCoparAhead' instead." #-}
943+runParallelT :: Monad m => CoparAheadT m a -> m ()
944+runParallelT = runStream . asCoparAhead
937945
938946-- | Same as @runStream . zipping@.
939947--
940948-- @since 0.1.0
941−{-# DEPRECATED runZipStream "Please use 'runStream . zipStreamly instead." #-}
949+{-# DEPRECATED runZipStream "Please use 'runStream . asZipStream instead." #-}
942950runZipStream :: Monad m => ZipStreamM m a -> m ()
943−runZipStream = runStream . zipStreamly
951+runZipStream = runStream . asZipStream
944952
945953-- | Same as @runStream . zippingAsync@.
946954--
947955-- @since 0.1.0
948−{-# DEPRECATED runZipAsync "Please use 'runStream . zipParallely instead." #-}
956+{-# DEPRECATED runZipAsync "Please use 'runStream . asZipParallel instead." #-}
949957runZipAsync :: Monad m => ZipParallelM m a -> m ()
950−runZipAsync = runStream . zipParallely
958+runZipAsync = runStream . asZipParallel
951959
952960------------------------------------------------------------------------------
953961-- IO Streams
@@ -965,24 +973,24 @@ type Stream a = StreamT IO a
965973-- @since 0.2.0
966974type Costream a = CostreamT IO a
967975
968−-- | A demand driven left biased parallelly composing IO stream of elements of
969−-- type @a@. See 'CoparallelT' documentation for more details.
976+-- | A demand driven left biased parallely composing IO stream of elements of
977+-- type @a@. See 'ParAheadT' documentation for more details.
970978--
971979-- @since 0.2.0
972−type Coparallel a = CoparallelT IO a
980+type ParAhead a = ParAheadT IO a
973981
974−-- | A round robin parallelly composing IO stream of elements of type @a@.
975−-- See 'ParallelT' documentation for more details.
982+-- | A round robin parallely composing IO stream of elements of type @a@.
983+-- See 'CoparAheadT' documentation for more details.
976984--
977985-- @since 0.2.0
978−type Parallel a = ParallelT IO a
986+type CoparAhead a = CoparAheadT IO a
979987
980988-- | An IO stream whose applicative instance zips streams serially.
981989--
982990-- @since 0.2.0
983991type ZipStream a = ZipStreamM IO a
984992
985−-- | An IO stream whose applicative instance zips streams parallely.
993+-- | An IO stream whose applicative instance zips streams asCoparAhead.
986994--
987995-- @since 0.2.0
988996type ZipParallel a = ZipParallelM IO a
@@ -994,7 +1002,7 @@ type ZipParallel a = ZipParallelM IO a
9941002-- | A variant of 'Data.Foldable.fold' that allows you to fold a 'Foldable'
9951003-- container of streams using the specified stream sum operation.
9961004--
997−-- @foldWith 'parallel' $ map return [1..3]@
1005+-- @foldWith 'parAhead' $ map return [1..3]@
9981006--
9991007-- @since 0.1.0
10001008{-# INLINABLE foldWith #-}
@@ -1006,7 +1014,7 @@ foldWith f = foldr f nil
10061014-- on a 'Foldable' container and then fold it using the specified stream sum
10071015-- operation.
10081016--
1009−-- @foldMapWith 'parallel' return [1..3]@
1017+-- @foldMapWith 'parAhead' return [1..3]@
10101018--
10111019-- @since 0.1.0
10121020{-# INLINABLE foldMapWith #-}
src/Streamly/Tutorial.hs+111−117
@@ -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
test/Main.hs+91−91
@@ -21,26 +21,26 @@ singleton :: IsStream t => a -> t m a
2121singleton a = a .: nil
2222
2323toListSerial :: StreamT IO a -> IO [a]
24−toListSerial = A.toList . streamly
24+toListSerial = A.toList . asStream
2525
2626toListInterleaved :: CostreamT IO a -> IO [a]
27−toListInterleaved = A.toList . costreamly
27+toListInterleaved = A.toList . asCostream
2828
29−toListAsync :: CoparallelT IO a -> IO [a]
30−toListAsync = A.toList . coparallely
29+toListAsync :: ParAheadT IO a -> IO [a]
30+toListAsync = A.toList . asParAhead
3131
32−toListParallel :: ParallelT IO a -> IO [a]
33−toListParallel = A.toList . parallely
32+toListParallel :: CoparAheadT IO a -> IO [a]
33+toListParallel = A.toList . asCoparAhead
3434
3535main :: IO ()
3636main = hspec $ do
3737 describe "Runners" $ do
3838 -- XXX move these to property tests
3939 -- XXX use an IORef to store and check the side effects
40− it "simple streamly" $
41− (runStream . streamly) (return (0 :: Int)) `shouldReturn` ()
42− it "simple streamly with IO" $
43− (runStream . streamly) (A.once $ putStrLn "hello") `shouldReturn` ()
40+ it "simple asStream" $
41+ (runStream . asStream) (return (0 :: Int)) `shouldReturn` ()
42+ it "simple asStream with IO" $
43+ (runStream . asStream) (A.once $ putStrLn "hello") `shouldReturn` ()
4444
4545 describe "Empty" $ do
4646 it "Monoid - mempty" $
@@ -96,27 +96,27 @@ main = hspec $ do
9696 -- for Monoid that is using the right version of semigroup. Instance
9797 -- deriving can cause us to pick wrong instances sometimes.
9898
99− describe "Serial interleaved (<>) ordering check" $ interleaveCheck costreamly (<>)
100− describe "Serial interleaved mappend ordering check" $ interleaveCheck costreamly mappend
99+ describe "Serial interleaved (<>) ordering check" $ interleaveCheck asCostream (<>)
100+ describe "Serial interleaved mappend ordering check" $ interleaveCheck asCostream mappend
101101
102− describe "Parallel interleaved (<>) ordering check" $ interleaveCheck parallely (<>)
103− describe "Parallel interleaved mappend ordering check" $ interleaveCheck parallely mappend
102+ describe "Parallel interleaved (<>) ordering check" $ interleaveCheck asCoparAhead (<>)
103+ describe "Parallel interleaved mappend ordering check" $ interleaveCheck asCoparAhead mappend
104104
105− describe "Coparallel (<>) time order check" $ parallelCheck coparallely (<>)
106− describe "Coparallel mappend time order check" $ parallelCheck coparallely mappend
107− describe "Parallel (<>) time order check" $ parallelCheck parallely (<>)
108− describe "Parallel mappend time order check" $ parallelCheck parallely mappend
105+ describe "Coparallel (<>) time order check" $ parallelCheck asParAhead (<>)
106+ describe "Coparallel mappend time order check" $ parallelCheck asParAhead mappend
107+ describe "Parallel (<>) time order check" $ parallelCheck asCoparAhead (<>)
108+ describe "Parallel mappend time order check" $ parallelCheck asCoparAhead mappend
109109
110110 ---------------------------------------------------------------------------
111111 -- Monoidal Compositions, multiset equality checks
112112 ---------------------------------------------------------------------------
113113
114− describe "Serial Composition" $ compose streamly mempty id
115− describe "Interleaved Composition" $ compose costreamly mempty sort
116− describe "Left biased parallel Composition" $ compose coparallely mempty sort
117− describe "Fair parallel Composition" $ compose parallely mempty sort
118− describe "Semigroup Composition for ZipSerial" $ compose zipStreamly mempty id
119− describe "Semigroup Composition for ZipAsync" $ compose zipParallely mempty id
114+ describe "Serial Composition" $ compose asStream mempty id
115+ describe "Interleaved Composition" $ compose asCostream mempty sort
116+ describe "Left biased parallel Composition" $ compose asParAhead mempty sort
117+ describe "Fair parallel Composition" $ compose asCoparAhead mempty sort
118+ describe "Semigroup Composition for ZipSerial" $ compose asZipStream mempty id
119+ describe "Semigroup Composition for ZipAsync" $ compose asZipParallel mempty id
120120 -- XXX need to check alternative compositions as well
121121
122122 ---------------------------------------------------------------------------
@@ -124,11 +124,11 @@ main = hspec $ do
124124 ---------------------------------------------------------------------------
125125
126126 -- TBD need more such combinations to be tested.
127− describe "<> and <>" $ composeAndComposeSimple streamly streamly (cycle [[1 .. 9]])
127+ describe "<> and <>" $ composeAndComposeSimple asStream asStream (cycle [[1 .. 9]])
128128
129129 describe "<> and <=>" $ composeAndComposeSimple
130− streamly
131− costreamly
130+ asStream
131+ asCostream
132132 ([ [1 .. 9]
133133 , [1 .. 9]
134134 , [1, 3, 2, 4, 6, 5, 7, 9, 8]
@@ -136,8 +136,8 @@ main = hspec $ do
136136 ])
137137
138138 describe "<=> and <=>" $ composeAndComposeSimple
139− costreamly
140− costreamly
139+ asCostream
140+ asCostream
141141 ([ [1, 4, 2, 7, 3, 5, 8, 6, 9]
142142 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
143143 , [1, 4, 3, 7, 2, 6, 9, 5, 8]
@@ -145,8 +145,8 @@ main = hspec $ do
145145 ])
146146
147147 describe "<=> and <>" $ composeAndComposeSimple
148− costreamly
149− streamly
148+ asCostream
149+ asStream
150150 ([ [1, 4, 2, 7, 3, 5, 8, 6, 9]
151151 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
152152 , [1, 4, 2, 7, 3, 5, 8, 6, 9]
@@ -155,8 +155,8 @@ main = hspec $ do
155155
156156 describe "Nested parallel and serial compositions" $ do
157157 let t = timed
158− p = parallely
159− s = streamly
158+ p = asCoparAhead
159+ s = asStream
160160 {-
161161 -- This is not correct, the result can also be [4,4,8,0,8,0,2,2]
162162 -- because of parallelism of [8,0] and [8,0].
@@ -168,7 +168,7 @@ main = hspec $ do
168168 `shouldReturn` ([4,4,8,8,0,0,2,2])
169169 -}
170170 it "Nest <|>, <>, <|> (2)" $
171− (A.toList . parallely) (
171+ (A.toList . asCoparAhead) (
172172 s (p (t 4 <> t 8) <> p (t 1 <> t 2))
173173 <> s (p (t 4 <> t 8) <> p (t 1 <> t 2)))
174174 `shouldReturn` ([4,4,8,8,1,1,2,2])
@@ -189,7 +189,7 @@ main = hspec $ do
189189 `shouldReturn` ([4,4,1,1,8,2,9,2])
190190 -}
191191 it "Nest <|>, <|>, <|>" $
192− (A.toList . parallely) (
192+ (A.toList . asCoparAhead) (
193193 ((t 4 <> t 8) <> (t 0 <> t 2))
194194 <> ((t 4 <> t 8) <> (t 0 <> t 2)))
195195 `shouldReturn` ([0,0,2,2,4,4,8,8])
@@ -198,73 +198,73 @@ main = hspec $ do
198198 -- Monoidal composition recursion loops
199199 ---------------------------------------------------------------------------
200200
201− describe "Serial loops (<>)" $ loops streamly id reverse
202− describe "Left biased parallel loops (<|)" $ loops coparallely sort sort
203− describe "Fair parallel loops (<|>)" $ loops parallely sort sort
201+ describe "Serial loops (<>)" $ loops asStream id reverse
202+ describe "Left biased parallel loops (<|)" $ loops asParAhead sort sort
203+ describe "Fair parallel loops (<|>)" $ loops asCoparAhead sort sort
204204
205205 ---------------------------------------------------------------------------
206206 -- Bind and monoidal composition combinations
207207 ---------------------------------------------------------------------------
208208
209− describe "Bind and compose1" $ bindAndComposeSimple streamly streamly
210− describe "Bind and compose2" $ bindAndComposeSimple streamly costreamly
211− describe "Bind and compose3" $ bindAndComposeSimple streamly coparallely
212− describe "Bind and compose4" $ bindAndComposeSimple streamly parallely
209+ describe "Bind and compose1" $ bindAndComposeSimple asStream asStream
210+ describe "Bind and compose2" $ bindAndComposeSimple asStream asCostream
211+ describe "Bind and compose3" $ bindAndComposeSimple asStream asParAhead
212+ describe "Bind and compose4" $ bindAndComposeSimple asStream asCoparAhead
213213
214− describe "Bind and compose1" $ bindAndComposeSimple costreamly streamly
215− describe "Bind and compose2" $ bindAndComposeSimple costreamly costreamly
216− describe "Bind and compose3" $ bindAndComposeSimple costreamly coparallely
217− describe "Bind and compose4" $ bindAndComposeSimple costreamly parallely
214+ describe "Bind and compose1" $ bindAndComposeSimple asCostream asStream
215+ describe "Bind and compose2" $ bindAndComposeSimple asCostream asCostream
216+ describe "Bind and compose3" $ bindAndComposeSimple asCostream asParAhead
217+ describe "Bind and compose4" $ bindAndComposeSimple asCostream asCoparAhead
218218
219− describe "Bind and compose1" $ bindAndComposeSimple coparallely streamly
220− describe "Bind and compose2" $ bindAndComposeSimple coparallely costreamly
221− describe "Bind and compose3" $ bindAndComposeSimple coparallely coparallely
222− describe "Bind and compose4" $ bindAndComposeSimple coparallely parallely
219+ describe "Bind and compose1" $ bindAndComposeSimple asParAhead asStream
220+ describe "Bind and compose2" $ bindAndComposeSimple asParAhead asCostream
221+ describe "Bind and compose3" $ bindAndComposeSimple asParAhead asParAhead
222+ describe "Bind and compose4" $ bindAndComposeSimple asParAhead asCoparAhead
223223
224− describe "Bind and compose1" $ bindAndComposeSimple parallely streamly
225− describe "Bind and compose2" $ bindAndComposeSimple parallely costreamly
226− describe "Bind and compose3" $ bindAndComposeSimple parallely coparallely
227− describe "Bind and compose4" $ bindAndComposeSimple parallely parallely
224+ describe "Bind and compose1" $ bindAndComposeSimple asCoparAhead asStream
225+ describe "Bind and compose2" $ bindAndComposeSimple asCoparAhead asCostream
226+ describe "Bind and compose3" $ bindAndComposeSimple asCoparAhead asParAhead
227+ describe "Bind and compose4" $ bindAndComposeSimple asCoparAhead asCoparAhead
228228
229229 let fldr, fldl :: (IsStream t, Semigroup (t IO Int)) => [t IO Int] -> t IO Int
230230 fldr = foldr (<>) nil
231231 fldl = foldl (<>) nil
232232
233233 forM_ [fldr, fldl] $ \k ->
234− describe "Bind and compose" $ bindAndComposeHierarchy streamly streamly k
234+ describe "Bind and compose" $ bindAndComposeHierarchy asStream asStream k
235235 forM_ [fldr, fldl] $ \k ->
236− describe "Bind and compose" $ bindAndComposeHierarchy streamly costreamly k
236+ describe "Bind and compose" $ bindAndComposeHierarchy asStream asCostream k
237237 forM_ [fldr, fldl] $ \k ->
238− describe "Bind and compose" $ bindAndComposeHierarchy streamly coparallely k
238+ describe "Bind and compose" $ bindAndComposeHierarchy asStream asParAhead k
239239 forM_ [fldr, fldl] $ \k ->
240− describe "Bind and compose" $ bindAndComposeHierarchy streamly parallely k
240+ describe "Bind and compose" $ bindAndComposeHierarchy asStream asCoparAhead k
241241
242242 forM_ [fldr, fldl] $ \k ->
243− describe "Bind and compose" $ bindAndComposeHierarchy costreamly streamly k
243+ describe "Bind and compose" $ bindAndComposeHierarchy asCostream asStream k
244244 forM_ [fldr, fldl] $ \k ->
245− describe "Bind and compose" $ bindAndComposeHierarchy costreamly costreamly k
245+ describe "Bind and compose" $ bindAndComposeHierarchy asCostream asCostream k
246246 forM_ [fldr, fldl] $ \k ->
247− describe "Bind and compose" $ bindAndComposeHierarchy costreamly coparallely k
247+ describe "Bind and compose" $ bindAndComposeHierarchy asCostream asParAhead k
248248 forM_ [fldr, fldl] $ \k ->
249− describe "Bind and compose" $ bindAndComposeHierarchy costreamly parallely k
249+ describe "Bind and compose" $ bindAndComposeHierarchy asCostream asCoparAhead k
250250
251251 forM_ [fldr, fldl] $ \k ->
252− describe "Bind and compose" $ bindAndComposeHierarchy coparallely streamly k
252+ describe "Bind and compose" $ bindAndComposeHierarchy asParAhead asStream k
253253 forM_ [fldr, fldl] $ \k ->
254− describe "Bind and compose" $ bindAndComposeHierarchy coparallely costreamly k
254+ describe "Bind and compose" $ bindAndComposeHierarchy asParAhead asCostream k
255255 forM_ [fldr, fldl] $ \k ->
256− describe "Bind and compose" $ bindAndComposeHierarchy coparallely coparallely k
256+ describe "Bind and compose" $ bindAndComposeHierarchy asParAhead asParAhead k
257257 forM_ [fldr, fldl] $ \k ->
258− describe "Bind and compose" $ bindAndComposeHierarchy coparallely parallely k
258+ describe "Bind and compose" $ bindAndComposeHierarchy asParAhead asCoparAhead k
259259
260260 forM_ [fldr, fldl] $ \k ->
261− describe "Bind and compose" $ bindAndComposeHierarchy parallely streamly k
261+ describe "Bind and compose" $ bindAndComposeHierarchy asCoparAhead asStream k
262262 forM_ [fldr, fldl] $ \k ->
263− describe "Bind and compose" $ bindAndComposeHierarchy parallely costreamly k
263+ describe "Bind and compose" $ bindAndComposeHierarchy asCoparAhead asCostream k
264264 forM_ [fldr, fldl] $ \k ->
265− describe "Bind and compose" $ bindAndComposeHierarchy parallely coparallely k
265+ describe "Bind and compose" $ bindAndComposeHierarchy asCoparAhead asParAhead k
266266 forM_ [fldr, fldl] $ \k ->
267− describe "Bind and compose" $ bindAndComposeHierarchy parallely parallely k
267+ describe "Bind and compose" $ bindAndComposeHierarchy asCoparAhead asCoparAhead k
268268
269269 -- Nest two lists using different styles of product compositions
270270 it "Nests two streams using monadic serial composition" nestTwoSerial
@@ -286,16 +286,16 @@ main = hspec $ do
286286 describe "Simple MonadError and MonadThrow" simpleMonadError
287287
288288 {-
289− describe "Composed MonadError streamly" $ composeWithMonadError streamly
290− describe "Composed MonadError costreamly" $ composeWithMonadError costreamly
291− describe "Composed MonadError coparallely" $ composeWithMonadError coparallely
292− describe "Composed MonadError parallely" $ composeWithMonadError parallely
289+ describe "Composed MonadError asStream" $ composeWithMonadError asStream
290+ describe "Composed MonadError asCostream" $ composeWithMonadError asCostream
291+ describe "Composed MonadError asParAhead" $ composeWithMonadError asParAhead
292+ describe "Composed MonadError asCoparAhead" $ composeWithMonadError asCoparAhead
293293 -}
294294
295− describe "Composed MonadThrow streamly" $ composeWithMonadThrow streamly
296− describe "Composed MonadThrow costreamly" $ composeWithMonadThrow costreamly
297− describe "Composed MonadThrow coparallely" $ composeWithMonadThrow coparallely
298− describe "Composed MonadThrow parallely" $ composeWithMonadThrow parallely
295+ describe "Composed MonadThrow asStream" $ composeWithMonadThrow asStream
296+ describe "Composed MonadThrow asCostream" $ composeWithMonadThrow asCostream
297+ describe "Composed MonadThrow asParAhead" $ composeWithMonadThrow asParAhead
298+ describe "Composed MonadThrow asCoparAhead" $ composeWithMonadThrow asCoparAhead
299299
300300-- XXX need to test that we have promptly cleaned up everything after the error
301301-- XXX We can also check the output that we are expected to get before the
@@ -334,16 +334,16 @@ composeWithMonadThrow t = do
334334 it "Compose nil, throwM" $
335335 (try $ tl (A.nil <> throwM (ExampleException "E")))
336336 `shouldReturn` (Left (ExampleException "E") :: Either ExampleException [Int])
337− oneLevelNestedSum "streamly" streamly
338− oneLevelNestedSum "costreamly" costreamly
339− oneLevelNestedSum "coparallely" coparallely
340− oneLevelNestedSum "parallely" parallely
337+ oneLevelNestedSum "asStream" asStream
338+ oneLevelNestedSum "asCostream" asCostream
339+ oneLevelNestedSum "asParAhead" asParAhead
340+ oneLevelNestedSum "asCoparAhead" asCoparAhead
341341 -- XXX add two level nesting
342342
343− oneLevelNestedProduct "streamly" streamly
344− oneLevelNestedProduct "costreamly" costreamly
345− oneLevelNestedProduct "coparallely" coparallely
346− oneLevelNestedProduct "parallely" parallely
343+ oneLevelNestedProduct "asStream" asStream
344+ oneLevelNestedProduct "asCostream" asCostream
345+ oneLevelNestedProduct "asParAhead" asParAhead
346+ oneLevelNestedProduct "asCoparAhead" asCoparAhead
347347
348348 where
349349 tl = A.toList . t
@@ -599,7 +599,7 @@ bindAndComposeHierarchy t1 t2 g = do
599599
600600 where
601601
602− -- bindComposeNested :: AParallelT IO Int
602+ -- bindComposeNested :: ACoparAheadT IO Int
603603 bindComposeNested =
604604 let c1 = tripleCompose (return 1) (return 2) (return 3)
605605 c2 = tripleCompose (return 4) (return 5) (return 6)
@@ -633,14 +633,14 @@ mixedOps = do
633633 x <- return 1
634634 y <- return 2
635635 z <- do
636− x1 <- parallely $ return 1 <> return 2
636+ x1 <- asCoparAhead $ return 1 <> return 2
637637 A.once $ return ()
638638 A.once $ putStr ""
639− y1 <- coparallely $ return 1 <> return 2
639+ y1 <- asParAhead $ return 1 <> return 2
640640 z1 <- do
641641 x11 <- return 1 <> return 2
642− y11 <- coparallely $ return 1 <> return 2
643− z11 <- costreamly $ return 1 <> return 2
642+ y11 <- asParAhead $ return 1 <> return 2
643+ z11 <- asCostream $ return 1 <> return 2
644644 A.once $ return ()
645645 A.once $ putStr ""
646646 return (x11 + y11 + z11)
test/Prop.hs+100−100
@@ -297,136 +297,136 @@ main :: IO ()
297297main = hspec $ do
298298 describe "Construction" $ do
299299 -- XXX test for all types of streams
300− prop "streamly replicateM" $ constructWithReplicateM streamly
300+ prop "asStream replicateM" $ constructWithReplicateM asStream
301301 it "iterate" $
302− (A.toList . streamly . (A.take 100) $ (A.iterate (+ 1) (0 :: Int)))
302+ (A.toList . asStream . (A.take 100) $ (A.iterate (+ 1) (0 :: Int)))
303303 `shouldReturn` (take 100 $ iterate (+ 1) 0)
304304
305305 it "iterateM" $ do
306306 let addM = (\ y -> return (y + 1))
307− A.toList . streamly . (A.take 100) $ A.iterateM addM (0 :: Int)
307+ A.toList . asStream . (A.take 100) $ A.iterateM addM (0 :: Int)
308308 `shouldReturn` (take 100 $ iterate (+ 1) 0)
309309
310310 let folded :: IsStream t => [a] -> t IO a
311− folded = streamly . (\xs ->
311+ folded = asStream . (\xs ->
312312 case xs of
313313 [x] -> return x -- singleton stream case
314314 _ -> foldMapWith (<>) return xs
315315 )
316316 describe "Functor operations" $ do
317− functorOps A.fromFoldable "streamly" streamly (==)
318− functorOps folded "streamly folded" streamly (==)
319− functorOps A.fromFoldable "costreamly" costreamly (==)
320− functorOps folded "costreamly folded" costreamly (==)
321− functorOps A.fromFoldable "coparallely" coparallely sortEq
322− functorOps folded "coparallely folded" coparallely sortEq
323− functorOps A.fromFoldable "parallely" parallely sortEq
324− functorOps folded "parallely folded" parallely sortEq
325− functorOps A.fromFoldable "zipStreamly" zipStreamly (==)
326− functorOps folded "zipStreamly folded" zipStreamly (==)
327− functorOps A.fromFoldable "zipParallely" zipParallely (==)
328− functorOps folded "zipParallely folded" zipParallely (==)
317+ functorOps A.fromFoldable "asStream" asStream (==)
318+ functorOps folded "asStream folded" asStream (==)
319+ functorOps A.fromFoldable "asCostream" asCostream (==)
320+ functorOps folded "asCostream folded" asCostream (==)
321+ functorOps A.fromFoldable "asParAhead" asParAhead sortEq
322+ functorOps folded "asParAhead folded" asParAhead sortEq
323+ functorOps A.fromFoldable "asCoparAhead" asCoparAhead sortEq
324+ functorOps folded "asCoparAhead folded" asCoparAhead sortEq
325+ functorOps A.fromFoldable "asZipStream" asZipStream (==)
326+ functorOps folded "asZipStream folded" asZipStream (==)
327+ functorOps A.fromFoldable "asZipParallel" asZipParallel (==)
328+ functorOps folded "asZipParallel folded" asZipParallel (==)
329329
330330 describe "Semigroup operations" $ do
331− semigroupOps "streamly" streamly (==)
332− semigroupOps "costreamly" costreamly (==)
333− semigroupOps "coparallely" coparallely sortEq
334− semigroupOps "parallely" parallely sortEq
335− semigroupOps "zipStreamly" zipStreamly (==)
336− semigroupOps "zipParallely" zipParallely (==)
331+ semigroupOps "asStream" asStream (==)
332+ semigroupOps "asCostream" asCostream (==)
333+ semigroupOps "asParAhead" asParAhead sortEq
334+ semigroupOps "asCoparAhead" asCoparAhead sortEq
335+ semigroupOps "asZipStream" asZipStream (==)
336+ semigroupOps "asZipParallel" asZipParallel (==)
337337
338338 describe "Applicative operations" $ do
339339 -- The tests using sorted equality are weaker tests
340340 -- We need to have stronger unit tests for all those
341341 -- XXX applicative with three arguments
342− prop "streamly applicative" $ applicativeOps A.fromFoldable streamly (==)
343− prop "streamly applicative folded" $ applicativeOps folded streamly (==)
344− prop "costreamly applicative" $ applicativeOps A.fromFoldable costreamly sortEq
345− prop "costreamly applicative folded" $ applicativeOps folded costreamly sortEq
346− prop "coparallely applicative" $ applicativeOps A.fromFoldable coparallely sortEq
347− prop "coparallely applicative folded" $ applicativeOps folded coparallely sortEq
348− prop "parallely applicative folded" $ applicativeOps folded parallely sortEq
342+ prop "asStream applicative" $ applicativeOps A.fromFoldable asStream (==)
343+ prop "asStream applicative folded" $ applicativeOps folded asStream (==)
344+ prop "asCostream applicative" $ applicativeOps A.fromFoldable asCostream sortEq
345+ prop "asCostream applicative folded" $ applicativeOps folded asCostream sortEq
346+ prop "asParAhead applicative" $ applicativeOps A.fromFoldable asParAhead sortEq
347+ prop "asParAhead applicative folded" $ applicativeOps folded asParAhead sortEq
348+ prop "asCoparAhead applicative folded" $ applicativeOps folded asCoparAhead sortEq
349349
350350 describe "Zip operations" $ do
351− prop "zipStreamly applicative" $ zipApplicative A.fromFoldable zipStreamly (==)
351+ prop "asZipStream applicative" $ zipApplicative A.fromFoldable asZipStream (==)
352352 -- XXX this hangs
353− -- prop "zipParallely applicative" $ zipApplicative zipParallely (==)
354− prop "zip monadic streamly" $ zipMonadic A.fromFoldable streamly (==)
355− prop "zip monadic streamly folded" $ zipMonadic folded streamly (==)
356− prop "zip monadic costreamly" $ zipMonadic A.fromFoldable costreamly (==)
357− prop "zip monadic costreamly folded" $ zipMonadic folded costreamly (==)
358− prop "zip monadic coparallely" $ zipMonadic A.fromFoldable coparallely (==)
359− prop "zip monadic coparallely folded" $ zipMonadic folded coparallely (==)
360− prop "zip monadic parallely" $ zipMonadic A.fromFoldable parallely (==)
361− prop "zip monadic parallely folded" $ zipMonadic folded parallely (==)
353+ -- prop "asZipParallel applicative" $ zipApplicative asZipParallel (==)
354+ prop "zip monadic asStream" $ zipMonadic A.fromFoldable asStream (==)
355+ prop "zip monadic asStream folded" $ zipMonadic folded asStream (==)
356+ prop "zip monadic asCostream" $ zipMonadic A.fromFoldable asCostream (==)
357+ prop "zip monadic asCostream folded" $ zipMonadic folded asCostream (==)
358+ prop "zip monadic asParAhead" $ zipMonadic A.fromFoldable asParAhead (==)
359+ prop "zip monadic asParAhead folded" $ zipMonadic folded asParAhead (==)
360+ prop "zip monadic asCoparAhead" $ zipMonadic A.fromFoldable asCoparAhead (==)
361+ prop "zip monadic asCoparAhead folded" $ zipMonadic folded asCoparAhead (==)
362362
363363 describe "Monad operations" $ do
364− prop "streamly monad then" $ monadThen A.fromFoldable streamly (==)
365− prop "costreamly monad then" $ monadThen A.fromFoldable costreamly sortEq
366− prop "coparallely monad then" $ monadThen A.fromFoldable coparallely sortEq
367− prop "parallely monad then" $ monadThen A.fromFoldable parallely sortEq
364+ prop "asStream monad then" $ monadThen A.fromFoldable asStream (==)
365+ prop "asCostream monad then" $ monadThen A.fromFoldable asCostream sortEq
366+ prop "asParAhead monad then" $ monadThen A.fromFoldable asParAhead sortEq
367+ prop "asCoparAhead monad then" $ monadThen A.fromFoldable asCoparAhead sortEq
368368
369− prop "streamly monad then folded" $ monadThen folded streamly (==)
370− prop "costreamly monad then folded" $ monadThen folded costreamly sortEq
371− prop "coparallely monad then folded" $ monadThen folded coparallely sortEq
372− prop "parallely monad then folded" $ monadThen folded parallely sortEq
369+ prop "asStream monad then folded" $ monadThen folded asStream (==)
370+ prop "asCostream monad then folded" $ monadThen folded asCostream sortEq
371+ prop "asParAhead monad then folded" $ monadThen folded asParAhead sortEq
372+ prop "asCoparAhead monad then folded" $ monadThen folded asCoparAhead sortEq
373373
374− prop "streamly monad bind" $ monadBind A.fromFoldable streamly (==)
375− prop "costreamly monad bind" $ monadBind A.fromFoldable costreamly sortEq
376− prop "coparallely monad bind" $ monadBind A.fromFoldable coparallely sortEq
377− prop "parallely monad bind" $ monadBind A.fromFoldable parallely sortEq
374+ prop "asStream monad bind" $ monadBind A.fromFoldable asStream (==)
375+ prop "asCostream monad bind" $ monadBind A.fromFoldable asCostream sortEq
376+ prop "asParAhead monad bind" $ monadBind A.fromFoldable asParAhead sortEq
377+ prop "asCoparAhead monad bind" $ monadBind A.fromFoldable asCoparAhead sortEq
378378
379379 describe "Stream transform operations" $ do
380− transformOps A.fromFoldable "streamly" streamly (==)
381− transformOps A.fromFoldable "costreamly" costreamly (==)
382− transformOps A.fromFoldable "zipStreamly" zipStreamly (==)
383− transformOps A.fromFoldable "zipParallely" zipParallely (==)
384− transformOps A.fromFoldable "coparallely" coparallely sortEq
385− transformOps A.fromFoldable "parallely" parallely sortEq
386−
387− transformOps folded "streamly folded" streamly (==)
388− transformOps folded "costreamly folded" costreamly (==)
389− transformOps folded "zipStreamly folded" zipStreamly (==)
390− transformOps folded "zipParallely folded" zipParallely (==)
391− transformOps folded "coparallely folded" coparallely sortEq
392− transformOps folded "parallely folded" parallely sortEq
393−
394− transformOpsWord8 A.fromFoldable "streamly" streamly
395− transformOpsWord8 A.fromFoldable "costreamly" costreamly
396− transformOpsWord8 A.fromFoldable "zipStreamly" zipStreamly
397− transformOpsWord8 A.fromFoldable "zipParallely" zipParallely
398− transformOpsWord8 A.fromFoldable "coparallely" coparallely
399− transformOpsWord8 A.fromFoldable "parallely" parallely
400−
401− transformOpsWord8 folded "streamly folded" streamly
402− transformOpsWord8 folded "costreamly folded" costreamly
403− transformOpsWord8 folded "zipStreamly folded" zipStreamly
404− transformOpsWord8 folded "zipParallely folded" zipParallely
405− transformOpsWord8 folded "coparallely folded" coparallely
406− transformOpsWord8 folded "parallely folded" parallely
380+ transformOps A.fromFoldable "asStream" asStream (==)
381+ transformOps A.fromFoldable "asCostream" asCostream (==)
382+ transformOps A.fromFoldable "asZipStream" asZipStream (==)
383+ transformOps A.fromFoldable "asZipParallel" asZipParallel (==)
384+ transformOps A.fromFoldable "asParAhead" asParAhead sortEq
385+ transformOps A.fromFoldable "asCoparAhead" asCoparAhead sortEq
386+
387+ transformOps folded "asStream folded" asStream (==)
388+ transformOps folded "asCostream folded" asCostream (==)
389+ transformOps folded "asZipStream folded" asZipStream (==)
390+ transformOps folded "asZipParallel folded" asZipParallel (==)
391+ transformOps folded "asParAhead folded" asParAhead sortEq
392+ transformOps folded "asCoparAhead folded" asCoparAhead sortEq
393+
394+ transformOpsWord8 A.fromFoldable "asStream" asStream
395+ transformOpsWord8 A.fromFoldable "asCostream" asCostream
396+ transformOpsWord8 A.fromFoldable "asZipStream" asZipStream
397+ transformOpsWord8 A.fromFoldable "asZipParallel" asZipParallel
398+ transformOpsWord8 A.fromFoldable "asParAhead" asParAhead
399+ transformOpsWord8 A.fromFoldable "asCoparAhead" asCoparAhead
400+
401+ transformOpsWord8 folded "asStream folded" asStream
402+ transformOpsWord8 folded "asCostream folded" asCostream
403+ transformOpsWord8 folded "asZipStream folded" asZipStream
404+ transformOpsWord8 folded "asZipParallel folded" asZipParallel
405+ transformOpsWord8 folded "asParAhead folded" asParAhead
406+ transformOpsWord8 folded "asCoparAhead folded" asCoparAhead
407407
408408 describe "Stream elimination operations" $ do
409− eliminationOps A.fromFoldable "streamly" streamly
410− eliminationOps A.fromFoldable "costreamly" costreamly
411− eliminationOps A.fromFoldable "zipStreamly" zipStreamly
412− eliminationOps A.fromFoldable "zipParallely" zipParallely
413− eliminationOps A.fromFoldable "coparallely" coparallely
414− eliminationOps A.fromFoldable "parallely" parallely
415−
416− eliminationOps folded "streamly folded" streamly
417− eliminationOps folded "costreamly folded" costreamly
418− eliminationOps folded "zipStreamly folded" zipStreamly
419− eliminationOps folded "zipParallely folded" zipParallely
420− eliminationOps folded "coparallely folded" coparallely
421− eliminationOps folded "parallely folded" parallely
409+ eliminationOps A.fromFoldable "asStream" asStream
410+ eliminationOps A.fromFoldable "asCostream" asCostream
411+ eliminationOps A.fromFoldable "asZipStream" asZipStream
412+ eliminationOps A.fromFoldable "asZipParallel" asZipParallel
413+ eliminationOps A.fromFoldable "asParAhead" asParAhead
414+ eliminationOps A.fromFoldable "asCoparAhead" asCoparAhead
415+
416+ eliminationOps folded "asStream folded" asStream
417+ eliminationOps folded "asCostream folded" asCostream
418+ eliminationOps folded "asZipStream folded" asZipStream
419+ eliminationOps folded "asZipParallel folded" asZipParallel
420+ eliminationOps folded "asParAhead folded" asParAhead
421+ eliminationOps folded "asCoparAhead folded" asCoparAhead
422422
423423 describe "Stream elimination operations" $ do
424− serialEliminationOps A.fromFoldable "streamly" streamly
425− serialEliminationOps A.fromFoldable "costreamly" costreamly
426− serialEliminationOps A.fromFoldable "zipStreamly" zipStreamly
427− serialEliminationOps A.fromFoldable "zipParallely" zipParallely
428−
429− serialEliminationOps folded "streamly folded" streamly
430− serialEliminationOps folded "costreamly folded" costreamly
431− serialEliminationOps folded "zipStreamly folded" zipStreamly
432− serialEliminationOps folded "zipParallely folded" zipParallely
424+ serialEliminationOps A.fromFoldable "asStream" asStream
425+ serialEliminationOps A.fromFoldable "asCostream" asCostream
426+ serialEliminationOps A.fromFoldable "asZipStream" asZipStream
427+ serialEliminationOps A.fromFoldable "asZipParallel" asZipParallel
428+
429+ serialEliminationOps folded "asStream folded" asStream
430+ serialEliminationOps folded "asCostream folded" asCostream
431+ serialEliminationOps folded "asZipStream folded" asZipStream
432+ serialEliminationOps folded "asZipParallel folded" asZipParallel
test/loops.hs+3−3
@@ -32,7 +32,7 @@ main = do
3232
3333 putStrLn $ "\nParallel interleave:\n"
3434 runStream $ do
35− x <- (return 0 <> return 1) `parallel` (return 100 <> return 101)
35+ x <- (return 0 <> return 1) `coparAhead` (return 100 <> return 101)
3636 once $ print (x :: Int)
3737
3838 where
@@ -63,12 +63,12 @@ main = do
6363 loopTailA :: Int -> Stream Int
6464 loopTailA x = do
6565 once $ putStrLn "LoopTailA..."
66− return x `coparallel` (if x < 3 then loopTailA (x + 1) else nil)
66+ return x `parAhead` (if x < 3 then loopTailA (x + 1) else nil)
6767
6868 loopHeadA :: Int -> Stream Int
6969 loopHeadA x = do
7070 once $ putStrLn "LoopHeadA..."
71− (if x < 3 then loopHeadA (x + 1) else nil) `coparallel` return x
71+ (if x < 3 then loopHeadA (x + 1) else nil) `parAhead` return x
7272
7373-------------------------------------------------------------------------------
7474-- Parallel (fairly scheduled, multi-threaded) stream generator loops
test/nested-loops.hs+1−1
@@ -21,4 +21,4 @@ main = runStream $ do
2121 rnd <- once (randomIO :: IO Int)
2222 let result = (name ++ show rnd)
2323 repeat = if n > 1 then loop name (n - 1) else nil
24− in (return result) `parallel` repeat
24+ in (return result) `coparAhead` repeat
test/parallel-loops.hs+2−2
@@ -7,7 +7,7 @@ import qualified Streamly.Prelude as S
77main = do
88 hSetBuffering stdout LineBuffering
99 runStream $ do
10− x <- S.take 10 $ loop "A" `parallel` loop "B"
10+ x <- S.take 10 $ loop "A" `coparAhead` loop "B"
1111 S.once $ myThreadId >>= putStr . show
1212 >> putStr " got "
1313 >> print x
@@ -23,4 +23,4 @@ main = do
2323 S.once $ myThreadId >>= putStr . show
2424 >> putStr " yielding "
2525 >> print rnd
26− return (name, rnd) `parallel` loop name
26+ return (name, rnd) `coparAhead` loop name