on master help sign in
rename streams with a consistent and intuitive scheme
74dd5a0Harendra Kumar
Changelog.md+13−7
@@ -39,21 +39,24 @@
39 * `MonadAsync` to `MonadParallel`
39 * `MonadAsync` to `MonadParallel`
40 * `Streaming` to `IsStream`
40 * `Streaming` to `IsStream`
41 * `runStreaming` to `runStream`
41 * `runStreaming` to `runStream`
42+ * `InterleavedT` to `CostreamT`
42− * `AsyncT` to `CoparallelT`
43+ * `AsyncT` to `ParAheadT`
43 * `ZipAsync` to `ZipParallelM`
44 * `ZipAsync` to `ZipParallelM`
45+ * `serially` to `asStream`
44− * `interleaving` to `costreamly`
46+ * `interleaving` to `asCostream`
45− * `asyncly` to `coparallely`
47+ * `asyncly` to `asParAhead`
48+ * `parallely` to `asParallel`
46− * `zipping` to `zipStreamly`
49+ * `zipping` to `asZipStream`
47− * `zippingAsync` to `zipParallely`
50+ * `zippingAsync` to `asZipParallel`
48 * `<=>` to `cosplice`
51 * `<=>` to `cosplice`
49− * `<|` to `coparallel`
52+ * `<|` to `parAhead`
50 * `each` to `fromFoldable`
53 * `each` to `fromFoldable`
51 * `scan` to `scanx`
54 * `scan` to `scanx`
52 * `foldl` to `foldx`
55 * `foldl` to `foldx`
53 * `foldlM` to `foldxM`
56 * `foldlM` to `foldxM`
54 * `zipAsyncWith` to `zipParallelWith`
57 * `zipAsyncWith` to `zipParallelWith`
55 * `zipAsyncWithM` to `zipParallelWithM`
58 * `zipAsyncWithM` to `zipParallelWithM`
56−* Deprecate and remove the following symbols:
59+* Deprecate the following symbols for future removal:
57 * `runStreamT`
60 * `runStreamT`
58 * `runInterleavedT`
61 * `runInterleavedT`
59 * `runAsyncT`
62 * `runAsyncT`
@@ -71,6 +74,9 @@
71 * `foldlM'` strict left fold with a monadic fold function
74 * `foldlM'` strict left fold with a monadic fold function
72 * `splice` run two streams serially one after the other
75 * `splice` run two streams serially one after the other
73 * `parallel` run two streams in parallel (replaces `<|>`)
76 * `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
74* Add simpler stream types that are specialized to the IO monad
80* Add simpler stream types that are specialized to the IO monad
75
81
76## 0.1.2
82## 0.1.2
benchmark/Linear.hs+4−4
@@ -50,10 +50,10 @@ main = do
50 ]
50 ]
51 , benchIO "zip" Ops.zip
51 , benchIO "zip" Ops.zip
52 , bgroup "append"
52 , bgroup "append"
53− [ benchIOAppend "streamly" $ Ops.append streamly
53+ [ benchIOAppend "asStream" $ Ops.append asStream
54− , benchIOAppend "costreamly" $ Ops.append costreamly
54+ , benchIOAppend "asCostream" $ Ops.append asCostream
55− , benchIOAppend "coparallely" $ Ops.append coparallely
55+ , benchIOAppend "asParAhead" $ Ops.append asParAhead
56− , benchIOAppend "parallely" $ Ops.append parallely
56+ , benchIOAppend "asCoparAhead" $ Ops.append asCoparAhead
57 ]
57 ]
58 , bgroup "compose"
58 , bgroup "compose"
59 [ benchIO "mapM" Ops.composeMapM
59 [ benchIO "mapM" Ops.composeMapM
benchmark/Nested.hs+43−43
@@ -27,55 +27,55 @@ main = do
27 , benchIO "toListLinear" Ops.toListLinear
27 , benchIO "toListLinear" Ops.toListLinear
28 ]
28 ]
29
29
30− , bgroup "streamly"
30+ , bgroup "asStream"
31− [ benchIO "append" $ Ops.append streamly
31+ [ benchIO "append" $ Ops.append asStream
32− , benchIO "toNull0" $ Ops.toNull0 streamly
32+ , benchIO "toNull0" $ Ops.toNull0 asStream
33− , benchIO "toList0" $ Ops.toList0 streamly
33+ , benchIO "toList0" $ Ops.toList0 asStream
34− , benchIO "toNull" $ Ops.toNull streamly
34+ , benchIO "toNull" $ Ops.toNull asStream
35− , benchIO "toList" $ Ops.toList streamly
35+ , benchIO "toList" $ Ops.toList asStream
36− , benchIO "toListSome" $ Ops.toListSome streamly
36+ , benchIO "toListSome" $ Ops.toListSome asStream
37− , benchIO "filterAllOut" $ Ops.filterAllOut streamly
37+ , benchIO "filterAllOut" $ Ops.filterAllOut asStream
38− , benchIO "filterAllIn" $ Ops.filterAllIn streamly
38+ , benchIO "filterAllIn" $ Ops.filterAllIn asStream
39− , benchIO "filterSome" $ Ops.filterSome streamly
39+ , benchIO "filterSome" $ Ops.filterSome asStream
40− , benchIO "breakAfterSome" $ Ops.breakAfterSome streamly
40+ , benchIO "breakAfterSome" $ Ops.breakAfterSome asStream
41 ]
41 ]
42
42
43− , bgroup "costreamly"
43+ , bgroup "asCostream"
44− [ benchIO "append" $ Ops.append costreamly
44+ [ benchIO "append" $ Ops.append asCostream
45− , benchIO "toNull0" $ Ops.toNull0 costreamly
45+ , benchIO "toNull0" $ Ops.toNull0 asCostream
46− , benchIO "toList0" $ Ops.toList0 costreamly
46+ , benchIO "toList0" $ Ops.toList0 asCostream
47− , benchIO "toNull" $ Ops.toNull costreamly
47+ , benchIO "toNull" $ Ops.toNull asCostream
48− , benchIO "toList" $ Ops.toList costreamly
48+ , benchIO "toList" $ Ops.toList asCostream
49− , benchIO "toListSome" $ Ops.toListSome costreamly
49+ , benchIO "toListSome" $ Ops.toListSome asCostream
50− , benchIO "filterAllOut" $ Ops.filterAllOut costreamly
50+ , benchIO "filterAllOut" $ Ops.filterAllOut asCostream
51− , benchIO "filterAllIn" $ Ops.filterAllIn costreamly
51+ , benchIO "filterAllIn" $ Ops.filterAllIn asCostream
52− , benchIO "filterSome" $ Ops.filterSome costreamly
52+ , benchIO "filterSome" $ Ops.filterSome asCostream
53− , benchIO "breakAfterSome" $ Ops.breakAfterSome costreamly
53+ , benchIO "breakAfterSome" $ Ops.breakAfterSome asCostream
54 ]
54 ]
55
55
56− , bgroup "Coparallely"
56+ , bgroup "CoasCoparAhead"
57− [ benchIO "append" $ Ops.append coparallely
57+ [ benchIO "append" $ Ops.append asParAhead
58− , benchIO "toNull0" $ Ops.toNull0 coparallely
58+ , benchIO "toNull0" $ Ops.toNull0 asParAhead
59− , benchIO "toList0" $ Ops.toList0 coparallely
59+ , benchIO "toList0" $ Ops.toList0 asParAhead
60− , benchIO "toNull" $ Ops.toNull coparallely
60+ , benchIO "toNull" $ Ops.toNull asParAhead
61− , benchIO "toList" $ Ops.toList coparallely
61+ , benchIO "toList" $ Ops.toList asParAhead
62− , benchIO "toListSome" $ Ops.toListSome coparallely
62+ , benchIO "toListSome" $ Ops.toListSome asParAhead
63− , benchIO "filterAllOut" $ Ops.filterAllOut coparallely
63+ , benchIO "filterAllOut" $ Ops.filterAllOut asParAhead
64− , benchIO "filterAllIn" $ Ops.filterAllIn coparallely
64+ , benchIO "filterAllIn" $ Ops.filterAllIn asParAhead
65− , benchIO "filterSome" $ Ops.filterSome coparallely
65+ , benchIO "filterSome" $ Ops.filterSome asParAhead
66− , benchIO "breakAfterSome" $ Ops.breakAfterSome coparallely
66+ , benchIO "breakAfterSome" $ Ops.breakAfterSome asParAhead
67 ]
67 ]
68
68
69 , bgroup "Parallely"
69 , bgroup "Parallely"
70− [ benchIO "append" $ Ops.append parallely
70+ [ benchIO "append" $ Ops.append asCoparAhead
71− , benchIO "toNull0" $ Ops.toNull0 parallely
71+ , benchIO "toNull0" $ Ops.toNull0 asCoparAhead
72− , benchIO "toList0" $ Ops.toList0 parallely
72+ , benchIO "toList0" $ Ops.toList0 asCoparAhead
73− , benchIO "toNull" $ Ops.toNull parallely
73+ , benchIO "toNull" $ Ops.toNull asCoparAhead
74− , benchIO "toList" $ Ops.toList parallely
74+ , benchIO "toList" $ Ops.toList asCoparAhead
75− , benchIO "toListSome" $ Ops.toListSome parallely
75+ , benchIO "toListSome" $ Ops.toListSome asCoparAhead
76− , benchIO "filterAllOut" $ Ops.filterAllOut parallely
76+ , benchIO "filterAllOut" $ Ops.filterAllOut asCoparAhead
77− , benchIO "filterAllIn" $ Ops.filterAllIn parallely
77+ , benchIO "filterAllIn" $ Ops.filterAllIn asCoparAhead
78− , benchIO "filterSome" $ Ops.filterSome parallely
78+ , benchIO "filterSome" $ Ops.filterSome asCoparAhead
79− , benchIO "breakAfterSome" $ Ops.breakAfterSome parallely
79+ , benchIO "breakAfterSome" $ Ops.breakAfterSome asCoparAhead
80 ]
80 ]
81 ]
81 ]
src/Streamly.hs+23−22
@@ -21,7 +21,7 @@
21-- in fact a synonym for @StreamT IO@. There are a few more types similar to
21-- in fact a synonym for @StreamT IO@. There are a few more types similar to
22-- 'StreamT', all of them represent a stream and differ only in the
22-- 'StreamT', all of them represent a stream and differ only in the
23-- 'Semigroup', 'Applicative' and 'Monad' compositions of the stream. 'Stream'
23-- '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'
25-- types compose concurrently. All these types can be freely inter-converted
25-- types compose concurrently. All these types can be freely inter-converted
26-- using type combinators without any cost. You can freely switch to any type
26-- using type combinators without any cost. You can freely switch to any type
27-- of composition at any point in the program. When no type annotation or
27-- of composition at any point in the program. When no type annotation or
@@ -65,10 +65,10 @@ module Streamly
65 , StreamT
65 , StreamT
66 , CostreamT
66 , CostreamT
67
67
68− -- ** Parallel Streams
68+ -- ** Parallel Ahead Streams
69− -- $parallel
69+ -- $parAhead
70− , CoparallelT
70+ , ParAheadT
71− , ParallelT
71+ , CoparAheadT
72
72
73 -- ** Zipping Streams
73 -- ** Zipping Streams
74 -- $zipping
74 -- $zipping
@@ -79,26 +79,26 @@ module Streamly
79 -- $sum
79 -- $sum
80 , splice
80 , splice
81 , cosplice
81 , cosplice
82− , coparallel
82+ , parAhead
83− , parallel
83+ , coparAhead
84
84
85 -- * Stream Type Adapters
85 -- * Stream Type Adapters
86 -- $adapters
86 -- $adapters
87 , IsStream
87 , IsStream
88
88
89− , streamly
89+ , asStream
90− , costreamly
90+ , asCostream
91− , coparallely
91+ , asParAhead
92− , parallely
92+ , asCoparAhead
93− , zipStreamly
93+ , asZipStream
94− , zipParallely
94+ , asZipParallel
95 , adapt
95 , adapt
96
96
97 -- * IO Streams
97 -- * IO Streams
98 , Stream
98 , Stream
99 , Costream
99 , Costream
100− , Coparallel
100+ , ParAhead
101− , Parallel
101+ , CoparAhead
102 , ZipStream
102 , ZipStream
103 , ZipParallel
103 , ZipParallel
104
104
@@ -132,6 +132,7 @@ module Streamly
132 , serially
132 , serially
133 , interleaving
133 , interleaving
134 , asyncly
134 , asyncly
135+ , parallely
135 , zipping
136 , zipping
136 , zippingAsync
137 , zippingAsync
137 , (<=>)
138 , (<=>)
@@ -151,12 +152,12 @@ import Data.Semigroup (Semigroup(..))
151-- streams are serial, the sequence of items in a composed stream can be solely
152-- streams are serial, the sequence of items in a composed stream can be solely
152-- determined by the position of elements in the consituent streams.
153-- determined by the position of elements in the consituent streams.
153
154
154−-- $parallel
155+-- $parAhead
155--
156--
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
157-- any point of time more than one stream can run concurrently and yield
158-- 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+-- elements. The two parallel ahead types 'ParAheadT' and 'coParAheadT' differ in how
159−-- they merge streams together in a 'Semigroup' or 'Monad' composition. As
160+-- they merge streams together in 'Semigroup' or 'Monad' compositions. As
160-- these streams compose concurrently, the sequence of items in a composed
161-- these streams compose concurrently, the sequence of items in a composed
161-- stream cannot be determined by the position of elements in the constituent
162-- stream cannot be determined by the position of elements in the constituent
162-- streams. The elements are yielded by the composed stream as they are
163-- streams. The elements are yielded by the composed stream as they are
@@ -184,10 +185,10 @@ import Data.Semigroup (Semigroup(..))
184-- one stream type to another. It is not used directly, instead the type
185-- one stream type to another. It is not used directly, instead the type
185-- combinators provided below are used for conversions.
186-- combinators provided below are used for conversions.
186--
187--
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
188-- type (e.g. 'StreamT') use the 'adapt' combinator. To give a polymorphic code
189-- type (e.g. 'StreamT') use the 'adapt' combinator. To give a polymorphic code
189-- a specific interpretation or to adapt a specific type to a polymorphic type
190-- 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
191-- cannot adapt polymorphic code to polymorphic code, as it would not know
192-- cannot adapt polymorphic code to polymorphic code, as it would not know
192-- which specific type you are converting from or to. If you see a an
193-- which specific type you are converting from or to. If you see a an
193-- @ambiguous type variable@ error then most likely you are using 'adapt'
194-- @ambiguous type variable@ error then most likely you are using 'adapt'
@@ -197,5 +198,5 @@ import Data.Semigroup (Semigroup(..))
197-- $foldutils
198-- $foldutils
198--
199--
199-- These are variants of standard 'Foldable' fold functions that use a
200-- 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
201-- container of streams.
202-- container of streams.
src/Streamly/Core.hs+12−12
@@ -35,8 +35,8 @@ module Streamly.Core
35 -- * Semigroup Style Composition
35 -- * Semigroup Style Composition
36 , splice
36 , splice
37 , cosplice
37 , cosplice
38− , coparallel
38+ , parAhead
39− , parallel
39+ , coparAhead
40
40
41 -- * Alternative
41 -- * Alternative
42 , alt
42 , alt
@@ -521,8 +521,8 @@ toStreamVar sv m = do
521--
521--
522-- TBD Note 2: We may want to run computations at the lower level of the
522-- TBD Note 2: We may want to run computations at the lower level of the
523-- composition tree serially even when they are composed using a parallel
523-- composition tree serially even when they are composed using a parallel
524−-- combinator. We can use 'splice' in place of 'coparallel' and 'cosplice' in
524+-- combinator. We can use 'splice' in place of 'parAhead' and 'cosplice' in
525−-- place of 'parallel'. If we find that an SVar immediately above a computation
525+-- place of 'coParAhead'. If we find that an SVar immediately above a computation
526-- gets drained empty we can switch to parallelizing the computation. For that
526-- gets drained empty we can switch to parallelizing the computation. For that
527-- we can use a state flag to fork the rest of the computation at any point of
527-- we can use a state flag to fork the rest of the computation at any point of
528-- time inside the Monad bind operation if the consumer is running at a faster
528-- 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
564-- Cases when we need to switch to a new SVar:
564-- Cases when we need to switch to a new SVar:
565--
565--
566-- * (x `parallel` y) `parallel` (t `parallel` u) -- all of them get scheduled on the same SVar
566-- * (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
568-- because of the scheduling policy change.
568-- 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
570-- 'Parallel', we create a new SVar at the transitioning bind.
570-- 'Parallel', we create a new SVar at the transitioning bind.
571-- * When the stream is switching from disjunctive composition to conjunctive
571-- * When the stream is switching from disjunctive composition to conjunctive
572-- composition and vice-versa we create a new SVar to isolate the scheduling
572-- 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 ->
585-- Semigroup and Monoid style compositions for parallel actions
585-- Semigroup and Monoid style compositions for parallel actions
586------------------------------------------------------------------------------
586------------------------------------------------------------------------------
587
587
588−{-# INLINE coparallel #-}
588+{-# INLINE parAhead #-}
589−coparallel :: MonadParallel m => Stream m a -> Stream m a -> Stream m a
589+parAhead :: MonadParallel m => Stream m a -> Stream m a -> Stream m a
590−coparallel = joinStreamVar2 (SVarStyle Disjunction LIFO)
590+parAhead = joinStreamVar2 (SVarStyle Disjunction LIFO)
591
591
592−{-# INLINE parallel #-}
592+{-# INLINE coparAhead #-}
593−parallel :: MonadParallel m => Stream m a -> Stream m a -> Stream m a
593+coparAhead :: MonadParallel m => Stream m a -> Stream m a -> Stream m a
594−parallel = joinStreamVar2 (SVarStyle Disjunction FIFO)
594+coparAhead = joinStreamVar2 (SVarStyle Disjunction FIFO)
595
595
596-------------------------------------------------------------------------------
596-------------------------------------------------------------------------------
597-- Functor instace is the same for all types
597-- Functor instace is the same for all types
src/Streamly/Streams.hs+131−123
@@ -54,16 +54,16 @@ module Streamly.Streams
54 -- * Merging Streams
54 -- * Merging Streams
55 , splice
55 , splice
56 , cosplice
56 , cosplice
57− , coparallel
57+ , parAhead
58− , parallel
58+ , coparAhead
59 , (<=>) --deprecated
59 , (<=>) --deprecated
60 , (<|) --deprecated
60 , (<|) --deprecated
61
61
62 -- * IO Streams
62 -- * IO Streams
63 , Stream
63 , Stream
64 , Costream
64 , Costream
65− , Coparallel
65+ , ParAhead
66− , Parallel
66+ , CoparAhead
67 , ZipStream
67 , ZipStream
68 , ZipParallel
68 , ZipParallel
69
69
@@ -71,24 +71,25 @@ module Streamly.Streams
71 , StreamT
71 , StreamT
72 , CostreamT
72 , CostreamT
73 , InterleavedT -- deprecated
73 , InterleavedT -- deprecated
74− , CoparallelT
74+ , ParAheadT
75 , AsyncT -- deprecated
75 , AsyncT -- deprecated
76− , ParallelT
76+ , CoparAheadT
77 , ZipStreamM
77 , ZipStreamM
78 , ZipParallelM
78 , ZipParallelM
79 , ZipAsync -- deprecated
79 , ZipAsync -- deprecated
80
80
81 -- * Type Adapters
81 -- * Type Adapters
82− , streamly
82+ , asStream
83 , serially -- deprecated
83 , serially -- deprecated
84− , costreamly
84+ , asCostream
85 , interleaving -- deprecated
85 , interleaving -- deprecated
86− , coparallely
86+ , asParAhead
87 , asyncly -- deprecated
87 , asyncly -- deprecated
88+ , asCoparAhead
88− , parallely
89+ , parallely -- deprecated
89− , zipStreamly
90+ , asZipStream
90 , zipping -- deprecated
91 , zipping -- deprecated
91− , zipParallely
92+ , asZipParallel
92 , zippingAsync -- deprecated
93 , zippingAsync -- deprecated
93 , adapt
94 , adapt
94
95
@@ -257,7 +258,7 @@ streamFold svr step single blank m =
257
258
258-- | Run a streaming composition, discard the results. By default it interprets
259-- | Run a streaming composition, discard the results. By default it interprets
259-- the stream as 'StreamT', to run other types of streams use the type adapting
260-- 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'@.
261--
262--
262-- @since 0.2.0
263-- @since 0.2.0
263runStream :: Monad m => StreamT m a -> m ()
264runStream :: Monad m => StreamT m a -> m ()
@@ -347,17 +348,17 @@ instance (MonadState s m CONSTRAINT) => MonadState s (STREAM m) where { \
347-- second stream.
348-- second stream.
348--
349--
349-- @
350-- @
350−-- main = ('toList' . 'streamly' $ (fromFoldable [1,2]) \<\> (fromFoldable [3,4])) >>= print
351+-- main = ('toList' . 'asStream' $ (fromFoldable [1,2]) \<\> (fromFoldable [3,4])) >>= print
351-- @
352-- @
352-- @
353-- @
353-- [1,2,3,4]
354-- [1,2,3,4]
354-- @
355-- @
355--
356--
356-- The 'Monad' instance runs the /monadic continuation/ for each
357-- The 'Monad' instance runs the /monadic continuation/ for each
357−-- element of the stream, streamly.
358+-- element of the stream, asStream.
358--
359--
359-- @
360-- @
360−-- main = 'runStream' . 'streamly' $ do
361+-- main = 'runStream' . 'asStream' $ do
361-- x <- return 1 \<\> return 2
362-- x <- return 1 \<\> return 2
362-- liftIO $ print x
363-- liftIO $ print x
363-- @
364-- @
@@ -366,10 +367,10 @@ instance (MonadState s m CONSTRAINT) => MonadState s (STREAM m) where { \
366-- 2
367-- 2
367-- @
368-- @
368--
369--
369−-- 'StreamT' nests streams streamly in a depth first manner.
370+-- 'StreamT' nests streams serially in a depth first manner.
370--
371--
371-- @
372-- @
372−-- main = 'runStream' . 'streamly' $ do
373+-- main = 'runStream' . 'asStream' $ do
373-- x <- return 1 \<\> return 2
374-- x <- return 1 \<\> return 2
374-- y <- return 3 \<\> return 4
375-- y <- return 3 \<\> return 4
375-- liftIO $ print (x, y)
376-- liftIO $ print (x, y)
@@ -387,7 +388,7 @@ instance (MonadState s m CONSTRAINT) => MonadState s (STREAM m) where { \
387-- nested @for@ loops and the monadic continuation is the body of the loop. The
388-- nested @for@ loops and the monadic continuation is the body of the loop. The
388-- loop iterates for all elements of the stream.
389-- loop iterates for all elements of the stream.
389--
390--
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
391-- 'StreamT'.
392-- 'StreamT'.
392-- Note that serial composition can be used to combine an infinite number of
393-- Note that serial composition can be used to combine an infinite number of
393-- streams as it explores only one stream at a time.
394-- streams as it explores only one stream at a time.
@@ -440,7 +441,7 @@ MONAD_COMMON_INSTANCES(StreamT,)
440-- yielding one element from each stream alternately.
441-- yielding one element from each stream alternately.
441--
442--
442-- @
443-- @
443−-- main = ('toList' . 'costreamly' $ (fromFoldable [1,2]) \<\> (fromFoldable [3,4])) >>= print
444+-- main = ('toList' . 'asCostream' $ (fromFoldable [1,2]) \<\> (fromFoldable [3,4])) >>= print
444-- @
445-- @
445-- @
446-- @
446-- [1,3,2,4]
447-- [1,3,2,4]
@@ -451,7 +452,7 @@ MONAD_COMMON_INSTANCES(StreamT,)
451--
452--
452--
453--
453-- @
454-- @
454−-- main = 'runStream' . 'costreamly' $ do
455+-- main = 'runStream' . 'asCostream' $ do
455-- x <- return 1 \<\> return 2
456-- x <- return 1 \<\> return 2
456-- y <- return 3 \<\> return 4
457-- y <- return 3 \<\> return 4
457-- liftIO $ print (x, y)
458-- liftIO $ print (x, y)
@@ -463,7 +464,7 @@ MONAD_COMMON_INSTANCES(StreamT,)
463-- (2,4)
464-- (2,4)
464-- @
465-- @
465--
466--
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
467-- streams as it needs to retain state for each unfinished stream.
468-- streams as it needs to retain state for each unfinished stream.
468--
469--
469-- @since 0.2.0
470-- @since 0.2.0
@@ -532,17 +533,17 @@ MONAD_APPLICATIVE_INSTANCE(CostreamT,)
532MONAD_COMMON_INSTANCES(CostreamT,)
533MONAD_COMMON_INSTANCES(CostreamT,)
533
534
534------------------------------------------------------------------------------
535------------------------------------------------------------------------------
535−-- CoparallelT
536+-- ParAheadT
536------------------------------------------------------------------------------
537------------------------------------------------------------------------------
537
538
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
539-- yield elements from the left stream as long as it can, but it can run the
540-- yield elements from the left stream as long as it can, but it can run the
540-- right stream in parallel if it needs to, based on demand. The right stream
541-- right stream in parallel if it needs to, based on demand. The right stream
541-- can be run if the left stream blocks on IO or cannot produce elements fast
542-- can be run if the left stream blocks on IO or cannot produce elements fast
542-- enough for the consumer.
543-- enough for the consumer.
543--
544--
544-- @
545-- @
545−-- main = ('toList' . 'coparallely' $ (fromFoldable [1,2]) \<> (fromFoldable [3,4])) >>= print
546+-- main = ('toList' . 'asParAhead' $ (fromFoldable [1,2]) \<> (fromFoldable [3,4])) >>= print
546-- @
547-- @
547-- @
548-- @
548-- [1,2,3,4]
549-- [1,2,3,4]
@@ -555,7 +556,7 @@ MONAD_COMMON_INSTANCES(CostreamT,)
555-- different streams in the resulting stream can vary depending on scheduling
556-- different streams in the resulting stream can vary depending on scheduling
556-- and generation delays.
557-- and generation delays.
557--
558--
558−-- Similarly, the monad instance of 'ParallelT' /may/ run each iteration
559+-- Similarly, the monad instance of 'CoparAheadT' /may/ run each iteration
559-- concurrently based on demand. More concurrent iterations are started only
560-- concurrently based on demand. More concurrent iterations are started only
560-- if the previous iterations are not able to produce enough output for the
561-- if the previous iterations are not able to produce enough output for the
561-- consumer.
562-- consumer.
@@ -564,7 +565,7 @@ MONAD_COMMON_INSTANCES(CostreamT,)
564-- import "Streamly"
565-- import "Streamly"
565-- import Control.Concurrent
566-- import Control.Concurrent
566--
567--
567−-- main = 'runStream' . 'coparallely' $ do
568+-- main = 'runStream' . 'asParAhead' $ do
568-- n <- return 3 \<\> return 2 \<\> return 1
569-- n <- return 3 \<\> return 2 \<\> return 1
569-- liftIO $ do
570-- liftIO $ do
570-- threadDelay (n * 1000000)
571-- threadDelay (n * 1000000)
@@ -582,47 +583,47 @@ MONAD_COMMON_INSTANCES(CostreamT,)
582-- as it explores only a bounded number of streams at a time.
583-- as it explores only a bounded number of streams at a time.
583--
584--
584-- @since 0.2.0
585-- @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}
586 deriving (Functor, MonadTrans)
587 deriving (Functor, MonadTrans)
587
588
588-- |
589-- |
589-- @since 0.1.0
590-- @since 0.1.0
590−{-# DEPRECATED AsyncT "Please use 'CoparallelT' instead." #-}
591+{-# DEPRECATED AsyncT "Please use 'ParAheadT' instead." #-}
591−type AsyncT = CoparallelT
592+type AsyncT = ParAheadT
592
593
593−instance IsStream CoparallelT where
594+instance IsStream ParAheadT where
594− toStream = getCoparallelT
595+ toStream = getParAheadT
595− fromStream = CoparallelT
596+ fromStream = ParAheadT
596
597
597------------------------------------------------------------------------------
598------------------------------------------------------------------------------
598-- Semigroup
599-- Semigroup
599------------------------------------------------------------------------------
600------------------------------------------------------------------------------
600
601
601−-- | Polymorphic version of the 'Semigroup' operation '<>' of 'CoparallelT'.
602+-- | Polymorphic version of the 'Semigroup' operation '<>' of 'ParAheadT'.
602-- Merges two streams possibly concurrently, preferring the
603-- Merges two streams possibly concurrently, preferring the
603-- elements from the left one when available.
604-- elements from the left one when available.
604--
605--
605-- @since 0.2.0
606-- @since 0.2.0
606−{-# INLINE coparallel #-}
607+{-# INLINE parAhead #-}
607−coparallel :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
608+parAhead :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
608−coparallel m1 m2 = fromStream $ S.coparallel (toStream m1) (toStream m2)
609+parAhead m1 m2 = fromStream $ S.parAhead (toStream m1) (toStream m2)
609
610
610−instance MonadParallel m => Semigroup (CoparallelT m a) where
611+instance MonadParallel m => Semigroup (ParAheadT m a) where
611− (<>) = coparallel
612+ (<>) = parAhead
612
613
613−-- | Same as 'coparallel'.
614+-- | Same as 'parAhead'.
614--
615--
615-- @since 0.1.0
616-- @since 0.1.0
616−{-# DEPRECATED (<|) "Please use 'coparallel' instead." #-}
617+{-# DEPRECATED (<|) "Please use 'parAhead' instead." #-}
617{-# INLINE (<|) #-}
618{-# INLINE (<|) #-}
618(<|) :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
619(<|) :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
619−(<|) = coparallel
620+(<|) = parAhead
620
621
621------------------------------------------------------------------------------
622------------------------------------------------------------------------------
622-- Monoid
623-- Monoid
623------------------------------------------------------------------------------
624------------------------------------------------------------------------------
624
625
625−instance MonadParallel m => Monoid (CoparallelT m a) where
626+instance MonadParallel m => Monoid (ParAheadT m a) where
626 mempty = nil
627 mempty = nil
627 mappend = (<>)
628 mappend = (<>)
628
629
@@ -645,29 +646,29 @@ parbind par m f = go m
645 yield a r = run $ f a `par` go r
646 yield a r = run $ f a `par` go r
646 in g Nothing stp single yield
647 in g Nothing stp single yield
647
648
648−instance MonadParallel m => Monad (CoparallelT m) where
649+instance MonadParallel m => Monad (ParAheadT m) where
649 return = pure
650 return = pure
650− (CoparallelT m) >>= f = CoparallelT $ parbind par m (getCoparallelT . f)
651+ (ParAheadT m) >>= f = ParAheadT $ parbind par m (getParAheadT . f)
651 where par = S.joinStreamVar2 (SVarStyle Conjunction LIFO)
652 where par = S.joinStreamVar2 (SVarStyle Conjunction LIFO)
652
653
653------------------------------------------------------------------------------
654------------------------------------------------------------------------------
654-- Other instances
655-- Other instances
655------------------------------------------------------------------------------
656------------------------------------------------------------------------------
656
657
657−MONAD_APPLICATIVE_INSTANCE(CoparallelT,MONADPARALLEL)
658+MONAD_APPLICATIVE_INSTANCE(ParAheadT,MONADPARALLEL)
658−MONAD_COMMON_INSTANCES(CoparallelT, MONADPARALLEL)
659+MONAD_COMMON_INSTANCES(ParAheadT, MONADPARALLEL)
659
660
660------------------------------------------------------------------------------
661------------------------------------------------------------------------------
661−-- ParallelT
662+-- CoparAheadT
662------------------------------------------------------------------------------
663------------------------------------------------------------------------------
663
664
664-- | Round robin concurrent composition.
665-- | Round robin concurrent composition.
665--
666--
666−-- The Semigroup instance of 'ParallelT' concurrently /merges/ streams in a
667+-- The Semigroup instance of 'CoparAheadT' concurrently /merges/ streams in a
667-- round robin fashion, yielding elements from both streams alternately.
668-- round robin fashion, yielding elements from both streams alternately.
668--
669--
669-- @
670-- @
670−-- main = ('toList' . 'parallely' $ (fromFoldable [1,2]) \<> (fromFoldable [3,4])) >>= print
671+-- main = ('toList' . 'asCoparAhead' $ (fromFoldable [1,2]) \<> (fromFoldable [3,4])) >>= print
671-- @
672-- @
672-- @
673-- @
673-- [1,3,2,4]
674-- [1,3,2,4]
@@ -680,14 +681,14 @@ MONAD_COMMON_INSTANCES(CoparallelT, MONADPARALLEL)
680-- different streams in the resulting stream can vary depending on scheduling
681-- different streams in the resulting stream can vary depending on scheduling
681-- and generation delays.
682-- and generation delays.
682--
683--
683−-- Similarly, the 'Monad' instance of 'ParallelT' runs /all/ iterations fairly
684+-- Similarly, the 'Monad' instance of 'CoparAheadT' runs /all/ iterations fairly
684-- concurrently using a round robin scheduling.
685-- concurrently using a round robin scheduling.
685--
686--
686-- @
687-- @
687-- import "Streamly"
688-- import "Streamly"
688-- import Control.Concurrent
689-- import Control.Concurrent
689--
690--
690−-- main = 'runStream' . 'parallely' $ do
691+-- main = 'runStream' . 'asCoparAhead' $ do
691-- n <- return 3 \<\> return 2 \<\> return 1
692-- n <- return 3 \<\> return 2 \<\> return 1
692-- liftIO $ do
693-- liftIO $ do
693-- threadDelay (n * 1000000)
694-- threadDelay (n * 1000000)
@@ -699,40 +700,40 @@ MONAD_COMMON_INSTANCES(CoparallelT, MONADPARALLEL)
699-- ThreadId 38: Delay 3
700-- ThreadId 38: Delay 3
700-- @
701-- @
701--
702--
702−-- Unlike 'CoparallelT' all iterations are guaranteed to run fairly
703+-- Unlike 'ParAheadT' all iterations are guaranteed to run fairly
703-- concurrently, unconditionally.
704-- concurrently, unconditionally.
704--
705--
705-- Note that round robin composition can only combine a finite number of
706-- Note that round robin composition can only combine a finite number of
706-- streams as it needs to retain state for each unfinished stream.
707-- streams as it needs to retain state for each unfinished stream.
707--
708--
708-- @since 0.1.0
709-- @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}
710 deriving (Functor, MonadTrans)
711 deriving (Functor, MonadTrans)
711
712
712−instance IsStream ParallelT where
713+instance IsStream CoparAheadT where
713− toStream = getParallelT
714+ toStream = getCoparAheadT
714− fromStream = ParallelT
715+ fromStream = CoparAheadT
715
716
716------------------------------------------------------------------------------
717------------------------------------------------------------------------------
717-- Semigroup
718-- Semigroup
718------------------------------------------------------------------------------
719------------------------------------------------------------------------------
719
720
720−-- | Polymorphic version of the 'Semigroup' operation '<>' of 'ParallelT'.
721+-- | Polymorphic version of the 'Semigroup' operation '<>' of 'CoparAheadT'.
721-- Merges two streams concurrently choosing elements from both fairly.
722-- Merges two streams concurrently choosing elements from both fairly.
722--
723--
723-- @since 0.2.0
724-- @since 0.2.0
724−{-# INLINE parallel #-}
725+{-# INLINE coparAhead #-}
725−parallel :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
726+coparAhead :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
726−parallel m1 m2 = fromStream $ S.parallel (toStream m1) (toStream m2)
727+coparAhead m1 m2 = fromStream $ S.coparAhead (toStream m1) (toStream m2)
727
728
728−instance MonadParallel m => Semigroup (ParallelT m a) where
729+instance MonadParallel m => Semigroup (CoparAheadT m a) where
729− (<>) = parallel
730+ (<>) = coparAhead
730
731
731------------------------------------------------------------------------------
732------------------------------------------------------------------------------
732-- Monoid
733-- Monoid
733------------------------------------------------------------------------------
734------------------------------------------------------------------------------
734
735
735−instance MonadParallel m => Monoid (ParallelT m a) where
736+instance MonadParallel m => Monoid (CoparAheadT m a) where
736 mempty = nil
737 mempty = nil
737 mappend = (<>)
738 mappend = (<>)
738
739
@@ -740,17 +741,17 @@ instance MonadParallel m => Monoid (ParallelT m a) where
740-- Monad
741-- Monad
741------------------------------------------------------------------------------
742------------------------------------------------------------------------------
742
743
743−instance MonadParallel m => Monad (ParallelT m) where
744+instance MonadParallel m => Monad (CoparAheadT m) where
744 return = pure
745 return = pure
745− (ParallelT m) >>= f = ParallelT $ parbind par m (getParallelT . f)
746+ (CoparAheadT m) >>= f = CoparAheadT $ parbind par m (getCoparAheadT . f)
746 where par = S.joinStreamVar2 (SVarStyle Conjunction FIFO)
747 where par = S.joinStreamVar2 (SVarStyle Conjunction FIFO)
747
748
748------------------------------------------------------------------------------
749------------------------------------------------------------------------------
749-- Other instances
750-- Other instances
750------------------------------------------------------------------------------
751------------------------------------------------------------------------------
751
752
752−MONAD_APPLICATIVE_INSTANCE(ParallelT,MONADPARALLEL)
753+MONAD_APPLICATIVE_INSTANCE(CoparAheadT,MONADPARALLEL)
753−MONAD_COMMON_INSTANCES(ParallelT, MONADPARALLEL)
754+MONAD_COMMON_INSTANCES(CoparAheadT, MONADPARALLEL)
754
755
755------------------------------------------------------------------------------
756------------------------------------------------------------------------------
756-- Serially Zipping Streams
757-- Serially Zipping Streams
@@ -761,7 +762,7 @@ MONAD_COMMON_INSTANCES(ParallelT, MONADPARALLEL)
761-- those elements.
762-- those elements.
762--
763--
763-- @
764-- @
764−-- main = (toList . 'zipStreamly' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
765+-- main = (toList . 'asZipStream' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
765-- where s1 = fromFoldable [1, 2]
766-- where s1 = fromFoldable [1, 2]
766-- s2 = fromFoldable [3, 4]
767-- s2 = fromFoldable [3, 4]
767-- s3 = fromFoldable [5, 6]
768-- s3 = fromFoldable [5, 6]
@@ -793,7 +794,7 @@ instance Monad m => Applicative (ZipStreamM m) where
793-- be zipped concurrently.
794-- be zipped concurrently.
794--
795--
795-- @
796-- @
796−-- main = (toList . 'zipParallely' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
797+-- main = (toList . 'asZipParallel' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
797-- where s1 = fromFoldable [1, 2]
798-- where s1 = fromFoldable [1, 2]
798-- s2 = fromFoldable [3, 4]
799-- s2 = fromFoldable [3, 4]
799-- s3 = fromFoldable [5, 6]
800-- s3 = fromFoldable [5, 6]
@@ -835,73 +836,80 @@ adapt = fromStream . toStream
835-- | Fix the type of a polymorphic stream as 'StreamT'.
836-- | Fix the type of a polymorphic stream as 'StreamT'.
836--
837--
837-- @since 0.2.0
838-- @since 0.2.0
838−streamly :: IsStream t => StreamT m a -> t m a
839+asStream :: IsStream t => StreamT m a -> t m a
839−streamly = adapt
840+asStream = adapt
840
841
841−-- | Same as 'streamly'.
842+-- | Same as 'asStream'.
842--
843--
843-- @since 0.1.0
844-- @since 0.1.0
844−{-# DEPRECATED serially "Please use streamly instead." #-}
845+{-# DEPRECATED serially "Please use asStream instead." #-}
845serially :: IsStream t => StreamT m a -> t m a
846serially :: IsStream t => StreamT m a -> t m a
846−serially = streamly
847+serially = asStream
847
848
848-- | Fix the type of a polymorphic stream as 'CostreamT'.
849-- | Fix the type of a polymorphic stream as 'CostreamT'.
849--
850--
850-- @since 0.2.0
851-- @since 0.2.0
851−costreamly :: IsStream t => CostreamT m a -> t m a
852+asCostream :: IsStream t => CostreamT m a -> t m a
852−costreamly = adapt
853+asCostream = adapt
853
854
854−-- | Same as 'costreamly'.
855+-- | Same as 'asCostream'.
855--
856--
856-- @since 0.1.0
857-- @since 0.1.0
857−{-# DEPRECATED interleaving "Please use costreamly instead." #-}
858+{-# DEPRECATED interleaving "Please use asCostream instead." #-}
858interleaving :: IsStream t => CostreamT m a -> t m a
859interleaving :: IsStream t => CostreamT m a -> t m a
859−interleaving = costreamly
860+interleaving = asCostream
860
861
861−-- | Fix the type of a polymorphic stream as 'CoparallelT'.
862+-- | Fix the type of a polymorphic stream as 'ParAheadT'.
862--
863--
863-- @since 0.2.0
864-- @since 0.2.0
864−coparallely :: IsStream t => CoparallelT m a -> t m a
865+asParAhead :: IsStream t => ParAheadT m a -> t m a
865−coparallely = adapt
866+asParAhead = adapt
866
867
867−-- | Same as 'coparallely'.
868+-- | Same as 'asParAhead'.
868--
869--
869-- @since 0.1.0
870-- @since 0.1.0
870−{-# DEPRECATED asyncly "Please use coparallely instead." #-}
871+{-# DEPRECATED asyncly "Please use asParAhead instead." #-}
871−asyncly :: IsStream t => CoparallelT m a -> t m a
872+asyncly :: IsStream t => ParAheadT m a -> t m a
872−asyncly = coparallely
873+asyncly = asParAhead
873
874
874−-- | Fix the type of a polymorphic stream as 'ParallelT'.
875+-- | Fix the type of a polymorphic stream as 'CoparAheadT'.
875--
876--
876-- @since 0.1.0
877-- @since 0.1.0
877−parallely :: IsStream t => ParallelT m a -> t m a
878+asCoparAhead :: IsStream t => CoparAheadT m a -> t m a
878−parallely = adapt
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
879
887
880-- | Fix the type of a polymorphic stream as 'ZipStreamM'.
888-- | Fix the type of a polymorphic stream as 'ZipStreamM'.
881--
889--
882-- @since 0.2.0
890-- @since 0.2.0
883−zipStreamly :: IsStream t => ZipStreamM m a -> t m a
891+asZipStream :: IsStream t => ZipStreamM m a -> t m a
884−zipStreamly = adapt
892+asZipStream = adapt
885
893
886−-- | Same as 'zipStreamly'.
894+-- | Same as 'asZipStream'.
887--
895--
888-- @since 0.1.0
896-- @since 0.1.0
889−{-# DEPRECATED zipping "Please use zipStreamly instead." #-}
897+{-# DEPRECATED zipping "Please use asZipStream instead." #-}
890zipping :: IsStream t => ZipStreamM m a -> t m a
898zipping :: IsStream t => ZipStreamM m a -> t m a
891−zipping = zipStreamly
899+zipping = asZipStream
892
900
893-- | Fix the type of a polymorphic stream as 'ZipParallelM'.
901-- | Fix the type of a polymorphic stream as 'ZipParallelM'.
894--
902--
895-- @since 0.2.0
903-- @since 0.2.0
896−zipParallely :: IsStream t => ZipParallelM m a -> t m a
904+asZipParallel :: IsStream t => ZipParallelM m a -> t m a
897−zipParallely = adapt
905+asZipParallel = adapt
898
906
899−-- | Same as 'zipParallely'.
907+-- | Same as 'asZipParallel'.
900--
908--
901-- @since 0.1.0
909-- @since 0.1.0
902−{-# DEPRECATED zippingAsync "Please use zipParallely instead." #-}
910+{-# DEPRECATED zippingAsync "Please use asZipParallel instead." #-}
903zippingAsync :: IsStream t => ZipParallelM m a -> t m a
911zippingAsync :: IsStream t => ZipParallelM m a -> t m a
904−zippingAsync = zipParallely
912+zippingAsync = asZipParallel
905
913
906-------------------------------------------------------------------------------
914-------------------------------------------------------------------------------
907-- Running Streams, convenience functions specialized to types
915-- Running Streams, convenience functions specialized to types
@@ -914,40 +922,40 @@ zippingAsync = zipParallely
914runStreamT :: Monad m => StreamT m a -> m ()
922runStreamT :: Monad m => StreamT m a -> m ()
915runStreamT = runStream
923runStreamT = runStream
916
924
917−-- | Same as @runStream . costreamly@.
925+-- | Same as @runStream . asCostream@.
918--
926--
919-- @since 0.1.0
927-- @since 0.1.0
920{-# DEPRECATED runInterleavedT "Please use 'runStream . interleaving' instead." #-}
928{-# DEPRECATED runInterleavedT "Please use 'runStream . interleaving' instead." #-}
921runInterleavedT :: Monad m => InterleavedT m a -> m ()
929runInterleavedT :: Monad m => InterleavedT m a -> m ()
922−runInterleavedT = runStream . costreamly
930+runInterleavedT = runStream . asCostream
923
931
924−-- | Same as @runStream . coparallely@.
932+-- | Same as @runStream . asParAhead@.
925--
933--
926-- @since 0.1.0
934-- @since 0.1.0
927−{-# DEPRECATED runAsyncT "Please use 'runStream . coparallely' instead." #-}
935+{-# DEPRECATED runAsyncT "Please use 'runStream . asParAhead' instead." #-}
928−runAsyncT :: Monad m => CoparallelT m a -> m ()
936+runAsyncT :: Monad m => ParAheadT m a -> m ()
929−runAsyncT = runStream . coparallely
937+runAsyncT = runStream . asParAhead
930
938
931−-- | Same as @runStream . parallely@.
939+-- | Same as @runStream . asCoparAhead@.
932--
940--
933-- @since 0.1.0
941-- @since 0.1.0
934−{-# DEPRECATED runParallelT "Please use 'runStream . parallely' instead." #-}
942+{-# DEPRECATED runParallelT "Please use 'runStream . asCoparAhead' instead." #-}
935−runParallelT :: Monad m => ParallelT m a -> m ()
943+runParallelT :: Monad m => CoparAheadT m a -> m ()
936−runParallelT = runStream . parallely
944+runParallelT = runStream . asCoparAhead
937
945
938-- | Same as @runStream . zipping@.
946-- | Same as @runStream . zipping@.
939--
947--
940-- @since 0.1.0
948-- @since 0.1.0
941−{-# DEPRECATED runZipStream "Please use 'runStream . zipStreamly instead." #-}
949+{-# DEPRECATED runZipStream "Please use 'runStream . asZipStream instead." #-}
942runZipStream :: Monad m => ZipStreamM m a -> m ()
950runZipStream :: Monad m => ZipStreamM m a -> m ()
943−runZipStream = runStream . zipStreamly
951+runZipStream = runStream . asZipStream
944
952
945-- | Same as @runStream . zippingAsync@.
953-- | Same as @runStream . zippingAsync@.
946--
954--
947-- @since 0.1.0
955-- @since 0.1.0
948−{-# DEPRECATED runZipAsync "Please use 'runStream . zipParallely instead." #-}
956+{-# DEPRECATED runZipAsync "Please use 'runStream . asZipParallel instead." #-}
949runZipAsync :: Monad m => ZipParallelM m a -> m ()
957runZipAsync :: Monad m => ZipParallelM m a -> m ()
950−runZipAsync = runStream . zipParallely
958+runZipAsync = runStream . asZipParallel
951
959
952------------------------------------------------------------------------------
960------------------------------------------------------------------------------
953-- IO Streams
961-- IO Streams
@@ -965,24 +973,24 @@ type Stream a = StreamT IO a
965-- @since 0.2.0
973-- @since 0.2.0
966type Costream a = CostreamT IO a
974type Costream a = CostreamT IO a
967
975
968−-- | A demand driven left biased parallelly composing IO stream of elements of
976+-- | A demand driven left biased parallely composing IO stream of elements of
969−-- type @a@. See 'CoparallelT' documentation for more details.
977+-- type @a@. See 'ParAheadT' documentation for more details.
970--
978--
971-- @since 0.2.0
979-- @since 0.2.0
972−type Coparallel a = CoparallelT IO a
980+type ParAhead a = ParAheadT IO a
973
981
974−-- | A round robin parallelly composing IO stream of elements of type @a@.
982+-- | A round robin parallely composing IO stream of elements of type @a@.
975−-- See 'ParallelT' documentation for more details.
983+-- See 'CoparAheadT' documentation for more details.
976--
984--
977-- @since 0.2.0
985-- @since 0.2.0
978−type Parallel a = ParallelT IO a
986+type CoparAhead a = CoparAheadT IO a
979
987
980-- | An IO stream whose applicative instance zips streams serially.
988-- | An IO stream whose applicative instance zips streams serially.
981--
989--
982-- @since 0.2.0
990-- @since 0.2.0
983type ZipStream a = ZipStreamM IO a
991type ZipStream a = ZipStreamM IO a
984
992
985−-- | An IO stream whose applicative instance zips streams parallely.
993+-- | An IO stream whose applicative instance zips streams asCoparAhead.
986--
994--
987-- @since 0.2.0
995-- @since 0.2.0
988type ZipParallel a = ZipParallelM IO a
996type ZipParallel a = ZipParallelM IO a
@@ -994,7 +1002,7 @@ type ZipParallel a = ZipParallelM IO a
994-- | A variant of 'Data.Foldable.fold' that allows you to fold a 'Foldable'
1002-- | A variant of 'Data.Foldable.fold' that allows you to fold a 'Foldable'
995-- container of streams using the specified stream sum operation.
1003-- container of streams using the specified stream sum operation.
996--
1004--
997−-- @foldWith 'parallel' $ map return [1..3]@
1005+-- @foldWith 'parAhead' $ map return [1..3]@
998--
1006--
999-- @since 0.1.0
1007-- @since 0.1.0
1000{-# INLINABLE foldWith #-}
1008{-# INLINABLE foldWith #-}
@@ -1006,7 +1014,7 @@ foldWith f = foldr f nil
1006-- on a 'Foldable' container and then fold it using the specified stream sum
1014-- on a 'Foldable' container and then fold it using the specified stream sum
1007-- operation.
1015-- operation.
1008--
1016--
1009−-- @foldMapWith 'parallel' return [1..3]@
1017+-- @foldMapWith 'parAhead' return [1..3]@
1010--
1018--
1011-- @since 0.1.0
1019-- @since 0.1.0
1012{-# INLINABLE foldMapWith #-}
1020{-# INLINABLE foldMapWith #-}
src/Streamly/Tutorial.hs+111−117
@@ -47,21 +47,20 @@ module Streamly.Tutorial
47 -- $transformation
47 -- $transformation
48
48
49 -- * Merging Streams
49 -- * Merging Streams
50− -- $combining
51
50
52 -- ** Semigroup Style
51 -- ** Semigroup Style
53 -- $semigroup
52 -- $semigroup
54
53
55− -- *** Serial Composition ('streamly')
54+ -- *** Serial Depth First Composition ('Stream')
56 -- $serial
55 -- $serial
57
56
58− -- *** Serial Interleaved Composition ('costreamly')
57+ -- *** Serial Breadth First Composition ('Costream')
59 -- $interleaved
58 -- $interleaved
60
59
61− -- *** Left Biased Concurrent Composition ('coparallely')
60+ -- *** Concurrent Depth First Composition ('ParAhead')
62− -- $coparallel
61+ -- $parAhead
63
62
64− -- *** Round Robin Concurrent Composition ('parallely')
63+ -- *** Concurrent Breadth First Composition ('CoParAhead')
65 -- $parallel
64 -- $parallel
66
65
67 -- *** Custom composition
66 -- *** Custom composition
@@ -76,16 +75,16 @@ module Streamly.Tutorial
76 -- ** Monad
75 -- ** Monad
77 -- $monad
76 -- $monad
78
77
79− -- *** Serial Nesting ('streamly')
78+ -- *** Serial Depth First Nesting ('Stream')
80 -- $regularSerial
79 -- $regularSerial
81
80
82− -- *** Serial Interleaved Nesting ('costreamly')
81+ -- *** Serial Breadth First Nesting ('Costream')
83 -- $interleavedNesting
82 -- $interleavedNesting
84
83
85− -- *** Left Biased Concurrent Nesting ('coparallely')
84+ -- *** Concurrent Depth First Nesting ('ParAhead')
86 -- $concurrentNesting
85 -- $concurrentNesting
87
86
88− -- *** Round Robin Concurrent Nesting ('parallely')
87+ -- *** Concurrent Breadth First Nesting ('CoparAhead')
89 -- $fairlyConcurrentNesting
88 -- $fairlyConcurrentNesting
90
89
91 -- *** Exercise
90 -- *** Exercise
@@ -156,7 +155,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
156-- in fact a synonym for @StreamT IO@. There are a few more types similar to
155-- in fact a synonym for @StreamT IO@. There are a few more types similar to
157-- 'StreamT' that all represent streams and differ only in the 'Semigroup',
156-- 'StreamT' that all represent streams and differ only in the 'Semigroup',
158-- 'Applicative' and 'Monad' compositions of the streams. 'Stream' and
157-- '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
160-- compose concurrently. All these types can be freely inter-converted using
159-- compose concurrently. All these types can be freely inter-converted using
161-- type combinators without any cost. You can freely switch to any type of
160-- type combinators without any cost. You can freely switch to any type of
162-- composition at any point in the program. When no type annotation or
161-- composition at any point in the program. When no type annotation or
@@ -190,7 +189,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
190-- @StreamT IO@.
189-- @StreamT IO@.
191--
190--
192-- Similarly we have monad transformer types for other stream types as well viz.
191-- Similarly we have monad transformer types for other stream types as well viz.
193−-- 'CostreamT', 'CoparallelT' and 'ParallelT'.
192+-- 'CostreamT', 'ParAheadT' and 'CoparAheadT'.
194--
193--
195-- To lift a value from an underlying monad in a monad transformer stack into a
194-- To lift a value from an underlying monad in a monad transformer stack into a
196-- singleton stream use 'lift' and to lift from an IO action use 'liftIO'.
195-- singleton stream use 'lift' and to lift from an IO action use 'liftIO'.
@@ -309,13 +308,13 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
309-- operation '<>'. Streams can be combined in many different ways as described
308-- operation '<>'. Streams can be combined in many different ways as described
310-- in the following sections, the '<>' operation behaves differently depending
309-- in the following sections, the '<>' operation behaves differently depending
311-- on the stream type in effect. Streamly streams can be of many
310-- 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',
313-- 'ZipStream', and 'ZipParallel'. The first four are monads whereas the last
312-- 'ZipStream', and 'ZipParallel'. The first four are monads whereas the last
314-- two are applicatives. These types can be freely converted from one to
313-- two are applicatives. These types can be freely converted from one to
315-- another to acheive the desired composition style. To force a particular
314-- another to acheive the desired composition style. To force a particular
316-- type of composition we coerce the stream type using the corresponding type
315-- type of composition we coerce the stream type using the corresponding type
317−-- adapting combinator from 'streamly', 'costreamly', 'coparallely',
316+-- adapting combinator from 'asStream', 'asCostream', 'asParAhead',
318−-- 'parallely', 'zipStreamly' or 'zipParallely'. The default stream type is
317+-- 'asCoparAhead', 'asZipStream' or 'asZipParallel'. The default stream type is
319-- 'Stream' unless you change it by using one of the combinators.
318-- 'Stream' unless you change it by using one of the combinators.
320--
319--
321-- To illustrate the concurrent vs serial composition aspects, we will use the
320-- To illustrate the concurrent vs serial composition aspects, we will use the
@@ -336,18 +335,20 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
336-- $serial
335-- $serial
337--
336--
338-- The 'Semigroup' operation '<>' of the 'Stream' type combines the two streams
337-- 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'
338+-- in a /serial depth first/ manner. We use the 'asStream' type combinator to
340−-- style of composition. We can also use the 'Stream' type annotation for the
339+-- effect 'Stream' style of composition. We can also use an explicit 'Stream'
341−-- stream type to acheive the same effect. However, since 'Stream' is the
340+-- type annotation for the stream to acheive the same effect. However, since
342−-- default type unless explicitly specified by using a combinator, we can
341+-- 'Stream' is the default type unless explicitly specified by using a
343−-- omit using an explicit combinator or type annotation for this style of
342+-- combinator, we can omit using an explicit combinator or type annotation for
344−-- composition.
343+-- this style of composition.
345--
344--
346-- When two streams with multiple elements are combined in this manner, the
345-- When two streams with multiple elements are combined in this manner, the
347-- monadic actions in the two streams are performed sequentially i.e. first all
346-- monadic actions in the two streams are performed sequentially i.e. first all
348-- actions in the first stream are performed sequentially and then all actions
347-- actions in the first stream are performed sequentially and then all actions
349−-- in the second stream are performed sequentially. The following example
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−-- prints the sequence 1, 2, 3, 4:
350+-- before we move to the next. The following example prints the sequence 1, 2,
351+-- 3, 4:
351--
352--
352-- @
353-- @
353-- main = 'runStream' $ (print 1 |: print 2 |: nil) <> (print 3 |: print 4 |: nil)
354-- main = 'runStream' $ (print 1 |: print 2 |: nil) <> (print 3 |: print 4 |: nil)
@@ -383,18 +384,18 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
383-- $interleaved
384-- $interleaved
384--
385--
385-- The 'Semigroup' operation '<>' of the 'Costream' type combines the two
386-- 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
387-- combinator to effect 'Costream' style of composition. We can also use the
388-- 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.
389--
390--
390−-- When two streams with multiple elements are combined in this manner, the
391+-- When two streams with multiple elements are combined in this manner, we
391−-- monadic actions in the two streams are performed in an interleaved manner
392+-- traverse all the streams in a breadth first manner i.e. one action from each
392−-- i.e. one action from the first stream is performed and its output yielded
393+-- stream is peformed and yielded to the resulting stream before we come back
393−-- and then one action from the second stream is performed and its output
394+-- to the first stream again and so on.
394−-- yielded, and so on. The following example prints the sequence 1, 3, 2, 4
395+-- The following example prints the sequence 1, 3, 2, 4
395--
396--
396-- @
397-- @
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)
398-- @
399-- @
399-- @
400-- @
400-- 1
401-- 1
@@ -409,7 +410,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
409-- thread and take a combined total of 6 seconds:
410-- thread and take a combined total of 6 seconds:
410--
411--
411-- @
412-- @
412−-- main = 'runStream' . 'costreamly' $ delay 3 <> delay 2 <> delay 1
413+-- main = 'runStream' . 'asCostream' $ delay 3 <> delay 2 <> delay 1
413-- @
414-- @
414-- @
415-- @
415-- ThreadId 36: Delay 3
416-- ThreadId 36: Delay 3
@@ -419,7 +420,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
419--
420--
420-- The polymorphic version of the 'Costream' binary operation '<>' is called
421-- The polymorphic version of the 'Costream' binary operation '<>' is called
421-- 'cosplice'. We can use 'cosplice' to join streams in an interleaved manner
422-- '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'
423-- combinator in the following example:
424-- combinator in the following example:
424--
425--
425-- @
426-- @
@@ -435,28 +436,27 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
435-- Note that this composition cannot be used to fold infinite number of streams
436-- Note that this composition cannot be used to fold infinite number of streams
436-- since it requires preserving the state until a stream is finished.
437-- since it requires preserving the state until a stream is finished.
437
438
438−-- $coparallel
439+-- $parAhead
439--
440--
440−-- The 'Semigroup' operation '<>' of the 'Coparallel' type combines the two
441+-- The 'Semigroup' operation '<>' of the 'ParAhead' type combines the two
441−-- streams in a left biased concurrent manner. We use the 'coparallel' type
442+-- streams in a depth first manner with parallel look ahead. We use the
442−-- combinator to effect 'Coparallel' style of composition. We can also use the
443+-- 'asParAhead' type combinator to effect 'ParAhead' style of composition. We
443−-- 'Coparallel' type annotation for the stream type to acheive the same effect.
444+-- can also use the 'ParAhead' type annotation for the stream type to acheive
445+-- the same effect.
444--
446--
445-- When two streams with multiple elements are combined in this manner, the
447-- When two streams with multiple elements are combined in this manner, the
446−-- monadic actions in the two streams can be performed concurrently
448+-- streams are traversed in depth first manner just like 'Stream', however it
447−-- /when needed/ with a bias towards the left stream i.e. actions from the left
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
448−-- stream are performed sequentially, if the left stream blocks or cannot
452+-- stream(s) is performed if the first stream blocks or if it cannot produce
449−-- generate enough output to keep the consumer of the stream busy then it can
453+-- output at the rate that is enough to meet the consumer demand. Multiple
450−-- execute actions from the right stream concurrently. The outputs of the
454+-- streams can be executed concurrently to meet the demand.
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,
455+-- In the following example the first stream does not block,
456-- therefore the first stream is completely exhausted before the second.
456-- therefore the first stream is completely exhausted before the second.
457--
457--
458-- @
458-- @
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)
460-- @
460-- @
461-- @
461-- @
462-- 1
462-- 1
@@ -470,7 +470,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
470-- and 3 would be yielded first and then 2 and 4 would be yielded.
470-- and 3 would be yielded first and then 2 and 4 would be yielded.
471--
471--
472-- @
472-- @
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)
474-- where p n = threadDelay 1000000 >> print n
474-- where p n = threadDelay 1000000 >> print n
475-- @
475-- @
476-- @
476-- @
@@ -485,7 +485,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
485-- shortest delay is printed first:
485-- shortest delay is printed first:
486--
486--
487-- @
487-- @
488−-- main = 'runStream' . 'coparallely' $ delay 3 '<>' delay 2 '<>' delay 1
488+-- main = 'runStream' . 'asParAhead' $ delay 3 '<>' delay 2 '<>' delay 1
489-- @
489-- @
490-- @
490-- @
491-- ThreadId 42: Delay 1
491-- ThreadId 42: Delay 1
@@ -504,7 +504,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
504-- second as all of the actions are concurrent.
504-- second as all of the actions are concurrent.
505--
505--
506-- @
506-- @
507−-- main = 'runStream' . 'coparallely' $ (delay 1 <> delay 2) <> (delay 3 <> delay 4)
507+-- main = 'runStream' . 'asParAhead' $ (delay 1 <> delay 2) <> (delay 3 <> delay 4)
508-- @
508-- @
509-- @
509-- @
510-- 1
510-- 1
@@ -521,7 +521,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
521-- even if none of them blocks:
521-- even if none of them blocks:
522--
522--
523-- @
523-- @
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)
525-- where traced m = S.'once' (myThreadId >>= print) >> return m
525-- where traced m = S.'once' (myThreadId >>= print) >> return m
526-- @
526-- @
527-- @
527-- @
@@ -533,13 +533,13 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
533-- Note that the order of printing in the above examples may change due to
533-- Note that the order of printing in the above examples may change due to
534-- variations in scheduling latencies for concurrent threads.
534-- variations in scheduling latencies for concurrent threads.
535--
535--
536−-- The polymorphic version of the 'Coparallel' binary operation '<>' is called
536+-- The polymorphic version of the 'ParAhead' binary operation '<>' is called
537−-- 'coparallel'. We can use 'coparallel' to join streams in a left biased
537+-- 'parAhead'. We can use 'parAhead' to join streams in a left biased
538-- adaptively concurrent manner irrespective of the type, notice that we have
538-- 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:
540--
540--
541-- @
541-- @
542−-- main = 'runStream' $ delay 3 \`coparallel` delay 2 \`coparallel` delay 1
542+-- main = 'runStream' $ delay 3 \`parAhead` delay 2 \`parAhead` delay 1
543-- @
543-- @
544-- @
544-- @
545-- ThreadId 42: Delay 1
545-- ThreadId 42: Delay 1
@@ -555,12 +555,12 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
555-- all computations at once for any reason 'Parallel' style must be used
555-- all computations at once for any reason 'Parallel' style must be used
556-- instead.
556-- instead.
557--
557--
558−-- 'Coparallel' style should be preferred over 'Parallel' unless you really
558+-- 'ParAhead' style should be preferred over 'CoparAhead' unless you really
559−-- need 'Parallel'. It utilizes the resources optimally. It should be used when
559+-- need 'CoparAhead'. It utilizes the resources optimally. It should be used when
560-- we know that the computations can run in parallel but we do not care if they
560-- we know that the computations can run in parallel but we do not care if they
561-- actually run in parallel or not, that decision can be left to the scheduler
561-- actually run in parallel or not, that decision can be left to the scheduler
562-- based on demand. Also, note that this operator can be used to fold infinite
562-- 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
564-- require us to run all of them at the same time in a fair manner.
564-- require us to run all of them at the same time in a fair manner.
565
565
566-- $parallel
566-- $parallel
@@ -586,7 +586,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
586-- import qualified Streamly.Prelude as S
586-- import qualified Streamly.Prelude as S
587-- import Network.HTTP.Simple
587-- import Network.HTTP.Simple
588--
588--
589−-- main = 'runStream' . 'parallely' $ google \<> bing \<> duckduckgo
589+-- main = 'runStream' . 'asParallel' $ google \<> bing \<> duckduckgo
590-- where
590-- where
591-- google = get "https://www.google.com/search?q=haskell"
591-- google = get "https://www.google.com/search?q=haskell"
592-- bing = get "https://www.bing.com/search?q=haskell"
592-- bing = get "https://www.bing.com/search?q=haskell"
@@ -594,12 +594,12 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
594-- get s = S.'once' (httpNoBody (parseRequest_ s) >> putStrLn (show s))
594-- get s = S.'once' (httpNoBody (parseRequest_ s) >> putStrLn (show s))
595-- @
595-- @
596--
596--
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
598-- yields outputs in the same order as the 'Costream' composition, though this
598-- yields outputs in the same order as the 'Costream' composition, though this
599-- is not always guaranteed because of thread scheduling variances.
599-- is not always guaranteed because of thread scheduling variances.
600--
600--
601-- @
601-- @
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)
603-- @
603-- @
604-- @
604-- @
605-- 1
605-- 1
@@ -608,13 +608,13 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
608-- 4
608-- 4
609-- @
609-- @
610--
610--
611−-- The polymorphic version of the 'Parallel' binary operation '<>' is called
611+-- The polymorphic version of the 'CoparAhead' binary operation '<>' is called
612−-- 'parallel'. We can use 'parallel' to join streams in a fairly
612+-- 'coparAhead'. We can use 'coparAhead' to join streams in a fairly
613-- concurrent manner irrespective of the type, notice that we have
613-- 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:
615--
615--
616-- @
616-- @
617−-- main = 'runStream' $ delay 3 \`parallel` delay 2 \`parallel` delay 1
617+-- main = 'runStream' $ delay 3 \`coparAhead` delay 2 \`coparAhead` delay 1
618-- @
618-- @
619-- @
619-- @
620-- ThreadId 42: Delay 1
620-- ThreadId 42: Delay 1
@@ -635,7 +635,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
635-- time. Take an example of a merge sort of two sorted streams. We need to
635-- time. Take an example of a merge sort of two sorted streams. We need to
636-- keep consuming items from the stream which has the lowest item in the sort
636-- keep consuming items from the stream which has the lowest item in the sort
637-- order. This can be achieved using async references to streams. See
637-- order. This can be achieved using async references to streams. See
638−-- "Streamly.Examples.MergeSortedStreams".
638+-- "MergeSort.hs" in the examples directory.
639
639
640-- $monoid
640-- $monoid
641--
641--
@@ -660,10 +660,10 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
660-- import Control.Concurrent
660-- import Control.Concurrent
661--
661--
662-- main = do
662-- main = do
663−-- 'runStream' $ 'parallely' $ foldMap delay [1..10]
663+-- 'runStream' $ 'asParAhead' $ foldMap delay [1..10]
664−-- 'runStream' $ 'foldWith' 'parallel' (map delay [1..10])
664+-- 'runStream' $ 'foldWith' 'parAhead' (map delay [1..10])
665−-- 'runStream' $ 'foldMapWith' 'parallel' delay [1..10]
665+-- 'runStream' $ 'foldMapWith' 'parAhead' delay [1..10]
666−-- 'runStream' $ 'forEachWith' 'parallel' [1..10] delay
666+-- 'runStream' $ 'forEachWith' 'parAhead' [1..10] delay
667-- where delay n = S.'once' $ threadDelay (n * 1000000) >> print n
667-- where delay n = S.'once' $ threadDelay (n * 1000000) >> print n
668-- @
668-- @
669
669
@@ -688,7 +688,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
688-- element in the first stream and for each element in the second stream
688-- element in the first stream and for each element in the second stream
689-- execute the body of the loop.
689-- execute the body of the loop.
690--
690--
691−-- The 'Monad' instances of 'Stream', 'Costream', 'Coparallel' and 'Parallel'
691+-- The 'Monad' instances of 'Stream', 'Costream', 'ParAhead' and 'CoparAhead'
692-- stream types support different flavors of nested looping. In other words,
692-- stream types support different flavors of nested looping. In other words,
693-- they are all variants of list transformer. The nesting behavior of these
693-- they are all variants of list transformer. The nesting behavior of these
694-- types exactly correspond to the way they merge streams as we discussed in
694-- types exactly correspond to the way they merge streams as we discussed in
@@ -763,22 +763,22 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
763
763
764-- $concurrentNesting
764-- $concurrentNesting
765--
765--
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
767-- loop concurrently. Concurrency is demand driven i.e. more concurrent
767-- loop concurrently. Concurrency is demand driven i.e. more concurrent
768-- iterations are started only if the previous iterations are not able to
768-- iterations are started only if the previous iterations are not able to
769-- produce enough output for the consumer of the output stream. This works
769-- 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.
771-- This is the concurrent analogue of 'Stream' style monadic composition.
771-- This is the concurrent analogue of 'Stream' style monadic composition.
772--
772--
773−-- The 'coparallely' type combinator can be used to switch to this
773+-- The 'asParAhead' type combinator can be used to switch to this
774-- style of composition. Alternatively, a type annotation can be used to
774-- 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'.
776--
776--
777-- @
777-- @
778-- import "Streamly"
778-- import "Streamly"
779-- import "Streamly.Prelude"
779-- import "Streamly.Prelude"
780--
780--
781−-- main = 'runStream' . 'coparallely' $ do
781+-- main = 'runStream' . 'asParAhead' $ do
782-- x <- 'fromFoldable' [3,2,1]
782-- x <- 'fromFoldable' [3,2,1]
783-- delay x
783-- delay x
784-- @
784-- @
@@ -794,7 +794,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
794-- When compared to imperative programming, this can be viewed as a @for@ loop
794-- When compared to imperative programming, this can be viewed as a @for@ loop
795-- with three concurrent iterations.
795-- with three concurrent iterations.
796--
796--
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.
798-- When multiple streams are composed using this style, the iterations are
798-- When multiple streams are composed using this style, the iterations are
799-- triggered in a DFS manner just like 'Stream' i.e. nested iterations are
799-- triggered in a DFS manner just like 'Stream' i.e. nested iterations are
800-- executed before we proceed to the next iteration at higher level. However,
800-- executed before we proceed to the next iteration at higher level. However,
@@ -805,7 +805,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
805-- import "Streamly"
805-- import "Streamly"
806-- import qualified "Streamly.Prelude" as S
806-- import qualified "Streamly.Prelude" as S
807--
807--
808−-- main = 'runStream' . 'coparallely' $ do
808+-- main = 'runStream' . 'asParAhead' $ do
809-- x <- S.'fromFoldable' [1,2]
809-- x <- S.'fromFoldable' [1,2]
810-- y <- S.'fromFoldable' [3,4]
810-- y <- S.'fromFoldable' [3,4]
811-- S.'once' $ putStrLn $ show (x, y)
811-- S.'once' $ putStrLn $ show (x, y)
@@ -821,8 +821,8 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
821--
821--
822-- The 'Monad' composition of 'Costream' type interleaves the iterations of
822-- The 'Monad' composition of 'Costream' type interleaves the iterations of
823-- outer and inner loops in a nested loop composition. This works exactly the
823-- 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
824+-- same way as the merging of two streams in 'asCostream' fashion works. The
825−-- 'costreamly' type combinator can be used to switch to this style of
825+-- 'asCostream' type combinator can be used to switch to this style of
826-- composition. Alternatively, a type annotation can be used to specify the
826-- composition. Alternatively, a type annotation can be used to specify the
827-- type of the stream as 'Costream'.
827-- type of the stream as 'Costream'.
828--
828--
@@ -830,7 +830,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
830-- import "Streamly"
830-- import "Streamly"
831-- import qualified "Streamly.Prelude" as S
831-- import qualified "Streamly.Prelude" as S
832--
832--
833−-- main = 'runStream' . 'costreamly' $ do
833+-- main = 'runStream' . 'asCostream' $ do
834-- x <- S.'fromFoldable' [1,2]
834-- x <- S.'fromFoldable' [1,2]
835-- y <- S.'fromFoldable' [3,4]
835-- y <- S.'fromFoldable' [3,4]
836-- S.once $ putStrLn $ show (x, y)
836-- S.once $ putStrLn $ show (x, y)
@@ -846,7 +846,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
846-- $fairlyConcurrentNesting
846-- $fairlyConcurrentNesting
847--
847--
848-- The 'Monad' composition of 'Parallel' type starts all the iterations of a
848-- 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'.
850-- This works exactly the same way as the merging streams 'parallely' works.
850-- This works exactly the same way as the merging streams 'parallely' works.
851-- The 'parallely' type combinator can be used to switch to this style of
851-- The 'parallely' type combinator can be used to switch to this style of
852-- composition. Alternatively, a type annotation can be used to specify the
852-- composition. Alternatively, a type annotation can be used to specify the
@@ -894,10 +894,10 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
894-- Now we can interpret this in whatever way we want:
894-- Now we can interpret this in whatever way we want:
895--
895--
896-- @
896-- @
897−-- main = 'runStream' . 'streamly' $ composed
897+-- main = 'runStream' . 'asStream' $ composed
898−-- main = 'runStream' . 'costreamly' $ composed
898+-- main = 'runStream' . 'asCostream' $ composed
899−-- main = 'runStream' . 'coparallely' $ composed
899+-- main = 'runStream' . 'asParAhead' $ composed
900−-- main = 'runStream' . 'parallely' $ composed
900+-- main = 'runStream' . 'asCoparAhead' $ composed
901-- @
901-- @
902--
902--
903-- As an exercise try to figure out the output of this code for each mode of
903-- 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))
937-- s2 = d 3 <> d 4
937-- s2 = d 3 <> d 4
938-- d n = delay n >> return n
938-- d n = delay n >> return n
939--
939--
940−-- main = (S.'toList' . 'streamly' $ (,) \<$> s1 \<*> s2) >>= print
940+-- main = (S.'toList' . 'asStream' $ (,) \<$> s1 \<*> s2) >>= print
941-- @
941-- @
942-- @
942-- @
943-- ThreadId 36: Delay 1
943-- ThreadId 36: Delay 1
@@ -953,7 +953,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
953-- order but since it is serial it takes a total of 17 seconds:
953-- order but since it is serial it takes a total of 17 seconds:
954--
954--
955-- @
955-- @
956−-- main = (S.'toList' . 'costreamly' $ (,) \<$> s1 \<*> s2) >>= print
956+-- main = (S.'toList' . 'asCostream' $ (,) \<$> s1 \<*> s2) >>= print
957-- @
957-- @
958-- @
958-- @
959-- ThreadId 36: Delay 1
959-- ThreadId 36: Delay 1
@@ -965,11 +965,11 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
965-- [(1,3),(2,3),(1,4),(2,4)]
965-- [(1,3),(2,3),(1,4),(2,4)]
966-- @
966-- @
967--
967--
968−-- 'Coparallel' can run the iterations concurrently and therefore takes a total
968+-- 'ParAhead' can run the iterations concurrently and therefore takes a total
969-- of 10 seconds (1 + 2 + 3 + 4):
969-- of 10 seconds (1 + 2 + 3 + 4):
970--
970--
971-- @
971-- @
972−-- main = (S.'toList' . 'coparallely' $ (,) \<$> s1 \<*> s2) >>= print
972+-- main = (S.'toList' . 'asParAhead' $ (,) \<$> s1 \<*> s2) >>= print
973-- @
973-- @
974-- @
974-- @
975-- ThreadId 34: Delay 1
975-- ThreadId 34: Delay 1
@@ -981,11 +981,11 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
981-- [(1,3),(2,3),(1,4),(2,4)]
981-- [(1,3),(2,3),(1,4),(2,4)]
982-- @
982-- @
983--
983--
984−-- Similalrly 'Parallel' as well can run the iterations concurrently and
984+-- Similalrly 'CoparAhead' as well can run the iterations concurrently and
985-- therefore takes a total of 10 seconds (1 + 2 + 3 + 4):
985-- therefore takes a total of 10 seconds (1 + 2 + 3 + 4):
986--
986--
987-- @
987-- @
988−-- main = (S.'toList' . 'parallely' $ (,) \<$> s1 \<*> s2) >>= print
988+-- main = (S.'toList' . 'asCoparAhead' $ (,) \<$> s1 \<*> s2) >>= print
989-- @
989-- @
990-- @
990-- @
991-- ThreadId 34: Delay 1
991-- ThreadId 34: Delay 1
@@ -999,21 +999,16 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
999
999
1000-- $compositionSummary
1000-- $compositionSummary
1001--
1001--
1002−-- The following table summarizes the types for monadic compositions and the
1002+-- The following table summarizes the types for monadic and sum style
1003−-- operators for sum style compositions. This table captures the essence of
1003+-- compositions.
1004−-- streamly.
1005--
1004--
1006-- @
1005-- @
1007-- +-----+--------------+--------------+
1006-- +-----+--------------+--------------+
1008-- | | Serial | Concurrent |
1007-- | | Serial | Concurrent |
1009-- +=====+==============+==============+
1008-- +=====+==============+==============+
1010−-- | DFS | 'Stream' | 'Coparallel' |
1009+-- | DFS | 'Stream' | 'ParAhead' |
1011−-- | +--------------+--------------+
1012−-- | | 'splice' | 'coparallel' |
1013-- +-----+--------------+--------------+
1010-- +-----+--------------+--------------+
1014−-- | BFS | 'Costream' | 'Parallel' |
1011+-- | BFS | 'Costream' | 'CoparAhead' |
1015−-- | +--------------+--------------+
1016−-- | | 'cosplice' | 'parallel' |
1017-- +-----+--------------+--------------+
1012-- +-----+--------------+--------------+
1018-- @
1013-- @
1019
1014
@@ -1029,7 +1024,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1029-- $serialzip
1024-- $serialzip
1030--
1025--
1031-- The applicative instance of 'ZipStream' type zips streams serially.
1026-- 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
1033-- zip composition:
1028-- zip composition:
1034--
1029--
1035-- @
1030-- @
@@ -1041,7 +1036,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1041-- s1 = 'streamly' $ d 1 <> d 2
1036-- s1 = 'streamly' $ d 1 <> d 2
1042-- s2 = 'streamly' $ d 3 <> d 4
1037-- s2 = 'streamly' $ d 3 <> d 4
1043--
1038--
1044−-- main = (S.'toList' . 'zipStreamly' $ (,) \<$> s1 \<*> s2) >>= print
1039+-- main = (S.'toList' . 'asZipStream' $ (,) \<$> s1 \<*> s2) >>= print
1045-- @
1040-- @
1046--
1041--
1047-- This takes total 10 seconds to zip, which is (1 + 2 + 3 + 4) since
1042-- 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))
1058-- $parallelzip
1053-- $parallelzip
1059--
1054--
1060-- The applicative instance of 'ZipParallel' type zips streams concurrently.
1055-- 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
1062-- zip composition:
1057-- zip composition:
1063--
1058--
1064--
1059--
@@ -1074,7 +1069,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1074--
1069--
1075-- main = do
1070-- main = do
1076-- hSetBuffering stdout LineBuffering
1071-- hSetBuffering stdout LineBuffering
1077−-- (S.'toList' . 'zipParallely' $ (,) \<$> s1 \<*> s2) >>= print
1072+-- (S.'toList' . 'asZipParallel' $ (,) \<$> s1 \<*> s2) >>= print
1078-- @
1073-- @
1079--
1074--
1080-- This takes 7 seconds to zip, which is max (1,3) + max (2,4) because 1 and 3
1075-- 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))
1098-- choose the desired type of concurrency.
1093-- choose the desired type of concurrency.
1099--
1094--
1100-- In the following example the squares of @x@ and @y@ are computed
1095-- 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
1102-- sum are computed serially because of the 'streamly' combinator. We can
1097-- sum are computed serially because of the 'streamly' combinator. We can
1103-- choose different combinators for the monadic processing and the stream
1098-- choose different combinators for the monadic processing and the stream
1104−-- generation, to control the concurrency. We can also use the 'coparallely'
1099+-- generation, to control the concurrency. We can also use the 'asParAhead'
1105−-- combinator instead of explicitly folding with 'coparallel'.
1100+-- combinator instead of explicitly folding with 'parAhead'.
1106--
1101--
1107-- @
1102-- @
1108-- import "Streamly"
1103-- import "Streamly"
@@ -1111,11 +1106,11 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1111--
1106--
1112-- main = do
1107-- main = do
1113-- z \<- S.'toList'
1108-- z \<- S.'toList'
1114−-- $ 'streamly' -- Serial monadic processing (sqrt below)
1109+-- $ 'asStream' -- Serial monadic processing (sqrt below)
1115-- $ do
1110-- $ do
1116−-- x2 \<- 'forEachWith' 'coparallel' [1..100] $ -- Concurrent @"for"@ loop
1111+-- x2 \<- 'forEachWith' 'parAhead' [1..100] $ -- Concurrent @"for"@ loop
1117-- \\x -> return $ x * x -- body of the loop
1112-- \\x -> return $ x * x -- body of the loop
1118−-- y2 \<- 'forEachWith' 'coparallel' [1..100] $
1113+-- y2 \<- 'forEachWith' 'parAhead' [1..100] $
1119-- \\y -> return $ y * y
1114-- \\y -> return $ y * y
1120-- return $ sqrt (x2 + y2)
1115-- return $ sqrt (x2 + y2)
1121-- print $ sum z
1116-- print $ sum z
@@ -1126,8 +1121,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1126-- and operators instead of the ugly pragmas.
1121-- and operators instead of the ugly pragmas.
1127--
1122--
1128-- For more concurrent programming examples see,
1123-- For more concurrent programming examples see,
1129−-- "Streamly.Examples.ListDirRecursive", "Streamly.Examples.MergeSortedStreams"
1124+-- "ListDir.hs", "MergeSort.hs" and "SearchQuery.hs" in the examples directory.
1130−-- and "Streamly.Examples.SearchEngineQuery".
1131
1125
1132-- $reactive
1126-- $reactive
1133--
1127--
@@ -1189,8 +1183,8 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1189-- return ()
1183-- return ()
1190-- @
1184-- @
1191--
1185--
1192−-- You can also find the source of this example in
1186+-- You can also find the source of this example in the examples directory as
1193−-- "Streamly.Examples.AcidRainGame". It has been adapted from Gabriel's
1187+-- "AcidRain.hs". It has been adapted from Gabriel's
1194-- <https://hackage.haskell.org/package/pipes-concurrency-2.0.8/docs/Pipes-Concurrent-Tutorial.html pipes-concurrency>
1188-- <https://hackage.haskell.org/package/pipes-concurrency-2.0.8/docs/Pipes-Concurrent-Tutorial.html pipes-concurrency>
1195-- package.
1189-- package.
1196-- This is much simpler compared to the pipes version because of the builtin
1190-- 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
21singleton a = a .: nil
21singleton a = a .: nil
22
22
23toListSerial :: StreamT IO a -> IO [a]
23toListSerial :: StreamT IO a -> IO [a]
24−toListSerial = A.toList . streamly
24+toListSerial = A.toList . asStream
25
25
26toListInterleaved :: CostreamT IO a -> IO [a]
26toListInterleaved :: CostreamT IO a -> IO [a]
27−toListInterleaved = A.toList . costreamly
27+toListInterleaved = A.toList . asCostream
28
28
29−toListAsync :: CoparallelT IO a -> IO [a]
29+toListAsync :: ParAheadT IO a -> IO [a]
30−toListAsync = A.toList . coparallely
30+toListAsync = A.toList . asParAhead
31
31
32−toListParallel :: ParallelT IO a -> IO [a]
32+toListParallel :: CoparAheadT IO a -> IO [a]
33−toListParallel = A.toList . parallely
33+toListParallel = A.toList . asCoparAhead
34
34
35main :: IO ()
35main :: IO ()
36main = hspec $ do
36main = hspec $ do
37 describe "Runners" $ do
37 describe "Runners" $ do
38 -- XXX move these to property tests
38 -- XXX move these to property tests
39 -- XXX use an IORef to store and check the side effects
39 -- XXX use an IORef to store and check the side effects
40− it "simple streamly" $
40+ it "simple asStream" $
41− (runStream . streamly) (return (0 :: Int)) `shouldReturn` ()
41+ (runStream . asStream) (return (0 :: Int)) `shouldReturn` ()
42− it "simple streamly with IO" $
42+ it "simple asStream with IO" $
43− (runStream . streamly) (A.once $ putStrLn "hello") `shouldReturn` ()
43+ (runStream . asStream) (A.once $ putStrLn "hello") `shouldReturn` ()
44
44
45 describe "Empty" $ do
45 describe "Empty" $ do
46 it "Monoid - mempty" $
46 it "Monoid - mempty" $
@@ -96,27 +96,27 @@ main = hspec $ do
96 -- for Monoid that is using the right version of semigroup. Instance
96 -- for Monoid that is using the right version of semigroup. Instance
97 -- deriving can cause us to pick wrong instances sometimes.
97 -- deriving can cause us to pick wrong instances sometimes.
98
98
99− describe "Serial interleaved (<>) ordering check" $ interleaveCheck costreamly (<>)
99+ describe "Serial interleaved (<>) ordering check" $ interleaveCheck asCostream (<>)
100− describe "Serial interleaved mappend ordering check" $ interleaveCheck costreamly mappend
100+ describe "Serial interleaved mappend ordering check" $ interleaveCheck asCostream mappend
101
101
102− describe "Parallel interleaved (<>) ordering check" $ interleaveCheck parallely (<>)
102+ describe "Parallel interleaved (<>) ordering check" $ interleaveCheck asCoparAhead (<>)
103− describe "Parallel interleaved mappend ordering check" $ interleaveCheck parallely mappend
103+ describe "Parallel interleaved mappend ordering check" $ interleaveCheck asCoparAhead mappend
104
104
105− describe "Coparallel (<>) time order check" $ parallelCheck coparallely (<>)
105+ describe "Coparallel (<>) time order check" $ parallelCheck asParAhead (<>)
106− describe "Coparallel mappend time order check" $ parallelCheck coparallely mappend
106+ describe "Coparallel mappend time order check" $ parallelCheck asParAhead mappend
107− describe "Parallel (<>) time order check" $ parallelCheck parallely (<>)
107+ describe "Parallel (<>) time order check" $ parallelCheck asCoparAhead (<>)
108− describe "Parallel mappend time order check" $ parallelCheck parallely mappend
108+ describe "Parallel mappend time order check" $ parallelCheck asCoparAhead mappend
109
109
110 ---------------------------------------------------------------------------
110 ---------------------------------------------------------------------------
111 -- Monoidal Compositions, multiset equality checks
111 -- Monoidal Compositions, multiset equality checks
112 ---------------------------------------------------------------------------
112 ---------------------------------------------------------------------------
113
113
114− describe "Serial Composition" $ compose streamly mempty id
114+ describe "Serial Composition" $ compose asStream mempty id
115− describe "Interleaved Composition" $ compose costreamly mempty sort
115+ describe "Interleaved Composition" $ compose asCostream mempty sort
116− describe "Left biased parallel Composition" $ compose coparallely mempty sort
116+ describe "Left biased parallel Composition" $ compose asParAhead mempty sort
117− describe "Fair parallel Composition" $ compose parallely mempty sort
117+ describe "Fair parallel Composition" $ compose asCoparAhead mempty sort
118− describe "Semigroup Composition for ZipSerial" $ compose zipStreamly mempty id
118+ describe "Semigroup Composition for ZipSerial" $ compose asZipStream mempty id
119− describe "Semigroup Composition for ZipAsync" $ compose zipParallely mempty id
119+ describe "Semigroup Composition for ZipAsync" $ compose asZipParallel mempty id
120 -- XXX need to check alternative compositions as well
120 -- XXX need to check alternative compositions as well
121
121
122 ---------------------------------------------------------------------------
122 ---------------------------------------------------------------------------
@@ -124,11 +124,11 @@ main = hspec $ do
124 ---------------------------------------------------------------------------
124 ---------------------------------------------------------------------------
125
125
126 -- TBD need more such combinations to be tested.
126 -- 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]])
128
128
129 describe "<> and <=>" $ composeAndComposeSimple
129 describe "<> and <=>" $ composeAndComposeSimple
130− streamly
130+ asStream
131− costreamly
131+ asCostream
132 ([ [1 .. 9]
132 ([ [1 .. 9]
133 , [1 .. 9]
133 , [1 .. 9]
134 , [1, 3, 2, 4, 6, 5, 7, 9, 8]
134 , [1, 3, 2, 4, 6, 5, 7, 9, 8]
@@ -136,8 +136,8 @@ main = hspec $ do
136 ])
136 ])
137
137
138 describe "<=> and <=>" $ composeAndComposeSimple
138 describe "<=> and <=>" $ composeAndComposeSimple
139− costreamly
139+ asCostream
140− costreamly
140+ asCostream
141 ([ [1, 4, 2, 7, 3, 5, 8, 6, 9]
141 ([ [1, 4, 2, 7, 3, 5, 8, 6, 9]
142 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
142 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
143 , [1, 4, 3, 7, 2, 6, 9, 5, 8]
143 , [1, 4, 3, 7, 2, 6, 9, 5, 8]
@@ -145,8 +145,8 @@ main = hspec $ do
145 ])
145 ])
146
146
147 describe "<=> and <>" $ composeAndComposeSimple
147 describe "<=> and <>" $ composeAndComposeSimple
148− costreamly
148+ asCostream
149− streamly
149+ asStream
150 ([ [1, 4, 2, 7, 3, 5, 8, 6, 9]
150 ([ [1, 4, 2, 7, 3, 5, 8, 6, 9]
151 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
151 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
152 , [1, 4, 2, 7, 3, 5, 8, 6, 9]
152 , [1, 4, 2, 7, 3, 5, 8, 6, 9]
@@ -155,8 +155,8 @@ main = hspec $ do
155
155
156 describe "Nested parallel and serial compositions" $ do
156 describe "Nested parallel and serial compositions" $ do
157 let t = timed
157 let t = timed
158− p = parallely
158+ p = asCoparAhead
159− s = streamly
159+ s = asStream
160 {-
160 {-
161 -- This is not correct, the result can also be [4,4,8,0,8,0,2,2]
161 -- This is not correct, the result can also be [4,4,8,0,8,0,2,2]
162 -- because of parallelism of [8,0] and [8,0].
162 -- because of parallelism of [8,0] and [8,0].
@@ -168,7 +168,7 @@ main = hspec $ do
168 `shouldReturn` ([4,4,8,8,0,0,2,2])
168 `shouldReturn` ([4,4,8,8,0,0,2,2])
169 -}
169 -}
170 it "Nest <|>, <>, <|> (2)" $
170 it "Nest <|>, <>, <|> (2)" $
171− (A.toList . parallely) (
171+ (A.toList . asCoparAhead) (
172 s (p (t 4 <> t 8) <> p (t 1 <> t 2))
172 s (p (t 4 <> t 8) <> p (t 1 <> t 2))
173 <> s (p (t 4 <> t 8) <> p (t 1 <> t 2)))
173 <> s (p (t 4 <> t 8) <> p (t 1 <> t 2)))
174 `shouldReturn` ([4,4,8,8,1,1,2,2])
174 `shouldReturn` ([4,4,8,8,1,1,2,2])
@@ -189,7 +189,7 @@ main = hspec $ do
189 `shouldReturn` ([4,4,1,1,8,2,9,2])
189 `shouldReturn` ([4,4,1,1,8,2,9,2])
190 -}
190 -}
191 it "Nest <|>, <|>, <|>" $
191 it "Nest <|>, <|>, <|>" $
192− (A.toList . parallely) (
192+ (A.toList . asCoparAhead) (
193 ((t 4 <> t 8) <> (t 0 <> t 2))
193 ((t 4 <> t 8) <> (t 0 <> t 2))
194 <> ((t 4 <> t 8) <> (t 0 <> t 2)))
194 <> ((t 4 <> t 8) <> (t 0 <> t 2)))
195 `shouldReturn` ([0,0,2,2,4,4,8,8])
195 `shouldReturn` ([0,0,2,2,4,4,8,8])
@@ -198,73 +198,73 @@ main = hspec $ do
198 -- Monoidal composition recursion loops
198 -- Monoidal composition recursion loops
199 ---------------------------------------------------------------------------
199 ---------------------------------------------------------------------------
200
200
201− describe "Serial loops (<>)" $ loops streamly id reverse
201+ describe "Serial loops (<>)" $ loops asStream id reverse
202− describe "Left biased parallel loops (<|)" $ loops coparallely sort sort
202+ describe "Left biased parallel loops (<|)" $ loops asParAhead sort sort
203− describe "Fair parallel loops (<|>)" $ loops parallely sort sort
203+ describe "Fair parallel loops (<|>)" $ loops asCoparAhead sort sort
204
204
205 ---------------------------------------------------------------------------
205 ---------------------------------------------------------------------------
206 -- Bind and monoidal composition combinations
206 -- Bind and monoidal composition combinations
207 ---------------------------------------------------------------------------
207 ---------------------------------------------------------------------------
208
208
209− describe "Bind and compose1" $ bindAndComposeSimple streamly streamly
209+ describe "Bind and compose1" $ bindAndComposeSimple asStream asStream
210− describe "Bind and compose2" $ bindAndComposeSimple streamly costreamly
210+ describe "Bind and compose2" $ bindAndComposeSimple asStream asCostream
211− describe "Bind and compose3" $ bindAndComposeSimple streamly coparallely
211+ describe "Bind and compose3" $ bindAndComposeSimple asStream asParAhead
212− describe "Bind and compose4" $ bindAndComposeSimple streamly parallely
212+ describe "Bind and compose4" $ bindAndComposeSimple asStream asCoparAhead
213
213
214− describe "Bind and compose1" $ bindAndComposeSimple costreamly streamly
214+ describe "Bind and compose1" $ bindAndComposeSimple asCostream asStream
215− describe "Bind and compose2" $ bindAndComposeSimple costreamly costreamly
215+ describe "Bind and compose2" $ bindAndComposeSimple asCostream asCostream
216− describe "Bind and compose3" $ bindAndComposeSimple costreamly coparallely
216+ describe "Bind and compose3" $ bindAndComposeSimple asCostream asParAhead
217− describe "Bind and compose4" $ bindAndComposeSimple costreamly parallely
217+ describe "Bind and compose4" $ bindAndComposeSimple asCostream asCoparAhead
218
218
219− describe "Bind and compose1" $ bindAndComposeSimple coparallely streamly
219+ describe "Bind and compose1" $ bindAndComposeSimple asParAhead asStream
220− describe "Bind and compose2" $ bindAndComposeSimple coparallely costreamly
220+ describe "Bind and compose2" $ bindAndComposeSimple asParAhead asCostream
221− describe "Bind and compose3" $ bindAndComposeSimple coparallely coparallely
221+ describe "Bind and compose3" $ bindAndComposeSimple asParAhead asParAhead
222− describe "Bind and compose4" $ bindAndComposeSimple coparallely parallely
222+ describe "Bind and compose4" $ bindAndComposeSimple asParAhead asCoparAhead
223
223
224− describe "Bind and compose1" $ bindAndComposeSimple parallely streamly
224+ describe "Bind and compose1" $ bindAndComposeSimple asCoparAhead asStream
225− describe "Bind and compose2" $ bindAndComposeSimple parallely costreamly
225+ describe "Bind and compose2" $ bindAndComposeSimple asCoparAhead asCostream
226− describe "Bind and compose3" $ bindAndComposeSimple parallely coparallely
226+ describe "Bind and compose3" $ bindAndComposeSimple asCoparAhead asParAhead
227− describe "Bind and compose4" $ bindAndComposeSimple parallely parallely
227+ describe "Bind and compose4" $ bindAndComposeSimple asCoparAhead asCoparAhead
228
228
229 let fldr, fldl :: (IsStream t, Semigroup (t IO Int)) => [t IO Int] -> t IO Int
229 let fldr, fldl :: (IsStream t, Semigroup (t IO Int)) => [t IO Int] -> t IO Int
230 fldr = foldr (<>) nil
230 fldr = foldr (<>) nil
231 fldl = foldl (<>) nil
231 fldl = foldl (<>) nil
232
232
233 forM_ [fldr, fldl] $ \k ->
233 forM_ [fldr, fldl] $ \k ->
234− describe "Bind and compose" $ bindAndComposeHierarchy streamly streamly k
234+ describe "Bind and compose" $ bindAndComposeHierarchy asStream asStream k
235 forM_ [fldr, fldl] $ \k ->
235 forM_ [fldr, fldl] $ \k ->
236− describe "Bind and compose" $ bindAndComposeHierarchy streamly costreamly k
236+ describe "Bind and compose" $ bindAndComposeHierarchy asStream asCostream k
237 forM_ [fldr, fldl] $ \k ->
237 forM_ [fldr, fldl] $ \k ->
238− describe "Bind and compose" $ bindAndComposeHierarchy streamly coparallely k
238+ describe "Bind and compose" $ bindAndComposeHierarchy asStream asParAhead k
239 forM_ [fldr, fldl] $ \k ->
239 forM_ [fldr, fldl] $ \k ->
240− describe "Bind and compose" $ bindAndComposeHierarchy streamly parallely k
240+ describe "Bind and compose" $ bindAndComposeHierarchy asStream asCoparAhead k
241
241
242 forM_ [fldr, fldl] $ \k ->
242 forM_ [fldr, fldl] $ \k ->
243− describe "Bind and compose" $ bindAndComposeHierarchy costreamly streamly k
243+ describe "Bind and compose" $ bindAndComposeHierarchy asCostream asStream k
244 forM_ [fldr, fldl] $ \k ->
244 forM_ [fldr, fldl] $ \k ->
245− describe "Bind and compose" $ bindAndComposeHierarchy costreamly costreamly k
245+ describe "Bind and compose" $ bindAndComposeHierarchy asCostream asCostream k
246 forM_ [fldr, fldl] $ \k ->
246 forM_ [fldr, fldl] $ \k ->
247− describe "Bind and compose" $ bindAndComposeHierarchy costreamly coparallely k
247+ describe "Bind and compose" $ bindAndComposeHierarchy asCostream asParAhead k
248 forM_ [fldr, fldl] $ \k ->
248 forM_ [fldr, fldl] $ \k ->
249− describe "Bind and compose" $ bindAndComposeHierarchy costreamly parallely k
249+ describe "Bind and compose" $ bindAndComposeHierarchy asCostream asCoparAhead k
250
250
251 forM_ [fldr, fldl] $ \k ->
251 forM_ [fldr, fldl] $ \k ->
252− describe "Bind and compose" $ bindAndComposeHierarchy coparallely streamly k
252+ describe "Bind and compose" $ bindAndComposeHierarchy asParAhead asStream k
253 forM_ [fldr, fldl] $ \k ->
253 forM_ [fldr, fldl] $ \k ->
254− describe "Bind and compose" $ bindAndComposeHierarchy coparallely costreamly k
254+ describe "Bind and compose" $ bindAndComposeHierarchy asParAhead asCostream k
255 forM_ [fldr, fldl] $ \k ->
255 forM_ [fldr, fldl] $ \k ->
256− describe "Bind and compose" $ bindAndComposeHierarchy coparallely coparallely k
256+ describe "Bind and compose" $ bindAndComposeHierarchy asParAhead asParAhead k
257 forM_ [fldr, fldl] $ \k ->
257 forM_ [fldr, fldl] $ \k ->
258− describe "Bind and compose" $ bindAndComposeHierarchy coparallely parallely k
258+ describe "Bind and compose" $ bindAndComposeHierarchy asParAhead asCoparAhead k
259
259
260 forM_ [fldr, fldl] $ \k ->
260 forM_ [fldr, fldl] $ \k ->
261− describe "Bind and compose" $ bindAndComposeHierarchy parallely streamly k
261+ describe "Bind and compose" $ bindAndComposeHierarchy asCoparAhead asStream k
262 forM_ [fldr, fldl] $ \k ->
262 forM_ [fldr, fldl] $ \k ->
263− describe "Bind and compose" $ bindAndComposeHierarchy parallely costreamly k
263+ describe "Bind and compose" $ bindAndComposeHierarchy asCoparAhead asCostream k
264 forM_ [fldr, fldl] $ \k ->
264 forM_ [fldr, fldl] $ \k ->
265− describe "Bind and compose" $ bindAndComposeHierarchy parallely coparallely k
265+ describe "Bind and compose" $ bindAndComposeHierarchy asCoparAhead asParAhead k
266 forM_ [fldr, fldl] $ \k ->
266 forM_ [fldr, fldl] $ \k ->
267− describe "Bind and compose" $ bindAndComposeHierarchy parallely parallely k
267+ describe "Bind and compose" $ bindAndComposeHierarchy asCoparAhead asCoparAhead k
268
268
269 -- Nest two lists using different styles of product compositions
269 -- Nest two lists using different styles of product compositions
270 it "Nests two streams using monadic serial composition" nestTwoSerial
270 it "Nests two streams using monadic serial composition" nestTwoSerial
@@ -286,16 +286,16 @@ main = hspec $ do
286 describe "Simple MonadError and MonadThrow" simpleMonadError
286 describe "Simple MonadError and MonadThrow" simpleMonadError
287
287
288 {-
288 {-
289− describe "Composed MonadError streamly" $ composeWithMonadError streamly
289+ describe "Composed MonadError asStream" $ composeWithMonadError asStream
290− describe "Composed MonadError costreamly" $ composeWithMonadError costreamly
290+ describe "Composed MonadError asCostream" $ composeWithMonadError asCostream
291− describe "Composed MonadError coparallely" $ composeWithMonadError coparallely
291+ describe "Composed MonadError asParAhead" $ composeWithMonadError asParAhead
292− describe "Composed MonadError parallely" $ composeWithMonadError parallely
292+ describe "Composed MonadError asCoparAhead" $ composeWithMonadError asCoparAhead
293 -}
293 -}
294
294
295− describe "Composed MonadThrow streamly" $ composeWithMonadThrow streamly
295+ describe "Composed MonadThrow asStream" $ composeWithMonadThrow asStream
296− describe "Composed MonadThrow costreamly" $ composeWithMonadThrow costreamly
296+ describe "Composed MonadThrow asCostream" $ composeWithMonadThrow asCostream
297− describe "Composed MonadThrow coparallely" $ composeWithMonadThrow coparallely
297+ describe "Composed MonadThrow asParAhead" $ composeWithMonadThrow asParAhead
298− describe "Composed MonadThrow parallely" $ composeWithMonadThrow parallely
298+ describe "Composed MonadThrow asCoparAhead" $ composeWithMonadThrow asCoparAhead
299
299
300-- XXX need to test that we have promptly cleaned up everything after the error
300-- XXX need to test that we have promptly cleaned up everything after the error
301-- XXX We can also check the output that we are expected to get before the
301-- XXX We can also check the output that we are expected to get before the
@@ -334,16 +334,16 @@ composeWithMonadThrow t = do
334 it "Compose nil, throwM" $
334 it "Compose nil, throwM" $
335 (try $ tl (A.nil <> throwM (ExampleException "E")))
335 (try $ tl (A.nil <> throwM (ExampleException "E")))
336 `shouldReturn` (Left (ExampleException "E") :: Either ExampleException [Int])
336 `shouldReturn` (Left (ExampleException "E") :: Either ExampleException [Int])
337− oneLevelNestedSum "streamly" streamly
337+ oneLevelNestedSum "asStream" asStream
338− oneLevelNestedSum "costreamly" costreamly
338+ oneLevelNestedSum "asCostream" asCostream
339− oneLevelNestedSum "coparallely" coparallely
339+ oneLevelNestedSum "asParAhead" asParAhead
340− oneLevelNestedSum "parallely" parallely
340+ oneLevelNestedSum "asCoparAhead" asCoparAhead
341 -- XXX add two level nesting
341 -- XXX add two level nesting
342
342
343− oneLevelNestedProduct "streamly" streamly
343+ oneLevelNestedProduct "asStream" asStream
344− oneLevelNestedProduct "costreamly" costreamly
344+ oneLevelNestedProduct "asCostream" asCostream
345− oneLevelNestedProduct "coparallely" coparallely
345+ oneLevelNestedProduct "asParAhead" asParAhead
346− oneLevelNestedProduct "parallely" parallely
346+ oneLevelNestedProduct "asCoparAhead" asCoparAhead
347
347
348 where
348 where
349 tl = A.toList . t
349 tl = A.toList . t
@@ -599,7 +599,7 @@ bindAndComposeHierarchy t1 t2 g = do
599
599
600 where
600 where
601
601
602− -- bindComposeNested :: AParallelT IO Int
602+ -- bindComposeNested :: ACoparAheadT IO Int
603 bindComposeNested =
603 bindComposeNested =
604 let c1 = tripleCompose (return 1) (return 2) (return 3)
604 let c1 = tripleCompose (return 1) (return 2) (return 3)
605 c2 = tripleCompose (return 4) (return 5) (return 6)
605 c2 = tripleCompose (return 4) (return 5) (return 6)
@@ -633,14 +633,14 @@ mixedOps = do
633 x <- return 1
633 x <- return 1
634 y <- return 2
634 y <- return 2
635 z <- do
635 z <- do
636− x1 <- parallely $ return 1 <> return 2
636+ x1 <- asCoparAhead $ return 1 <> return 2
637 A.once $ return ()
637 A.once $ return ()
638 A.once $ putStr ""
638 A.once $ putStr ""
639− y1 <- coparallely $ return 1 <> return 2
639+ y1 <- asParAhead $ return 1 <> return 2
640 z1 <- do
640 z1 <- do
641 x11 <- return 1 <> return 2
641 x11 <- return 1 <> return 2
642− y11 <- coparallely $ return 1 <> return 2
642+ y11 <- asParAhead $ return 1 <> return 2
643− z11 <- costreamly $ return 1 <> return 2
643+ z11 <- asCostream $ return 1 <> return 2
644 A.once $ return ()
644 A.once $ return ()
645 A.once $ putStr ""
645 A.once $ putStr ""
646 return (x11 + y11 + z11)
646 return (x11 + y11 + z11)
test/Prop.hs+100−100
@@ -297,136 +297,136 @@ main :: IO ()
297main = hspec $ do
297main = hspec $ do
298 describe "Construction" $ do
298 describe "Construction" $ do
299 -- XXX test for all types of streams
299 -- XXX test for all types of streams
300− prop "streamly replicateM" $ constructWithReplicateM streamly
300+ prop "asStream replicateM" $ constructWithReplicateM asStream
301 it "iterate" $
301 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)))
303 `shouldReturn` (take 100 $ iterate (+ 1) 0)
303 `shouldReturn` (take 100 $ iterate (+ 1) 0)
304
304
305 it "iterateM" $ do
305 it "iterateM" $ do
306 let addM = (\ y -> return (y + 1))
306 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)
308 `shouldReturn` (take 100 $ iterate (+ 1) 0)
308 `shouldReturn` (take 100 $ iterate (+ 1) 0)
309
309
310 let folded :: IsStream t => [a] -> t IO a
310 let folded :: IsStream t => [a] -> t IO a
311− folded = streamly . (\xs ->
311+ folded = asStream . (\xs ->
312 case xs of
312 case xs of
313 [x] -> return x -- singleton stream case
313 [x] -> return x -- singleton stream case
314 _ -> foldMapWith (<>) return xs
314 _ -> foldMapWith (<>) return xs
315 )
315 )
316 describe "Functor operations" $ do
316 describe "Functor operations" $ do
317− functorOps A.fromFoldable "streamly" streamly (==)
317+ functorOps A.fromFoldable "asStream" asStream (==)
318− functorOps folded "streamly folded" streamly (==)
318+ functorOps folded "asStream folded" asStream (==)
319− functorOps A.fromFoldable "costreamly" costreamly (==)
319+ functorOps A.fromFoldable "asCostream" asCostream (==)
320− functorOps folded "costreamly folded" costreamly (==)
320+ functorOps folded "asCostream folded" asCostream (==)
321− functorOps A.fromFoldable "coparallely" coparallely sortEq
321+ functorOps A.fromFoldable "asParAhead" asParAhead sortEq
322− functorOps folded "coparallely folded" coparallely sortEq
322+ functorOps folded "asParAhead folded" asParAhead sortEq
323− functorOps A.fromFoldable "parallely" parallely sortEq
323+ functorOps A.fromFoldable "asCoparAhead" asCoparAhead sortEq
324− functorOps folded "parallely folded" parallely sortEq
324+ functorOps folded "asCoparAhead folded" asCoparAhead sortEq
325− functorOps A.fromFoldable "zipStreamly" zipStreamly (==)
325+ functorOps A.fromFoldable "asZipStream" asZipStream (==)
326− functorOps folded "zipStreamly folded" zipStreamly (==)
326+ functorOps folded "asZipStream folded" asZipStream (==)
327− functorOps A.fromFoldable "zipParallely" zipParallely (==)
327+ functorOps A.fromFoldable "asZipParallel" asZipParallel (==)
328− functorOps folded "zipParallely folded" zipParallely (==)
328+ functorOps folded "asZipParallel folded" asZipParallel (==)
329
329
330 describe "Semigroup operations" $ do
330 describe "Semigroup operations" $ do
331− semigroupOps "streamly" streamly (==)
331+ semigroupOps "asStream" asStream (==)
332− semigroupOps "costreamly" costreamly (==)
332+ semigroupOps "asCostream" asCostream (==)
333− semigroupOps "coparallely" coparallely sortEq
333+ semigroupOps "asParAhead" asParAhead sortEq
334− semigroupOps "parallely" parallely sortEq
334+ semigroupOps "asCoparAhead" asCoparAhead sortEq
335− semigroupOps "zipStreamly" zipStreamly (==)
335+ semigroupOps "asZipStream" asZipStream (==)
336− semigroupOps "zipParallely" zipParallely (==)
336+ semigroupOps "asZipParallel" asZipParallel (==)
337
337
338 describe "Applicative operations" $ do
338 describe "Applicative operations" $ do
339 -- The tests using sorted equality are weaker tests
339 -- The tests using sorted equality are weaker tests
340 -- We need to have stronger unit tests for all those
340 -- We need to have stronger unit tests for all those
341 -- XXX applicative with three arguments
341 -- XXX applicative with three arguments
342− prop "streamly applicative" $ applicativeOps A.fromFoldable streamly (==)
342+ prop "asStream applicative" $ applicativeOps A.fromFoldable asStream (==)
343− prop "streamly applicative folded" $ applicativeOps folded streamly (==)
343+ prop "asStream applicative folded" $ applicativeOps folded asStream (==)
344− prop "costreamly applicative" $ applicativeOps A.fromFoldable costreamly sortEq
344+ prop "asCostream applicative" $ applicativeOps A.fromFoldable asCostream sortEq
345− prop "costreamly applicative folded" $ applicativeOps folded costreamly sortEq
345+ prop "asCostream applicative folded" $ applicativeOps folded asCostream sortEq
346− prop "coparallely applicative" $ applicativeOps A.fromFoldable coparallely sortEq
346+ prop "asParAhead applicative" $ applicativeOps A.fromFoldable asParAhead sortEq
347− prop "coparallely applicative folded" $ applicativeOps folded coparallely sortEq
347+ prop "asParAhead applicative folded" $ applicativeOps folded asParAhead sortEq
348− prop "parallely applicative folded" $ applicativeOps folded parallely sortEq
348+ prop "asCoparAhead applicative folded" $ applicativeOps folded asCoparAhead sortEq
349
349
350 describe "Zip operations" $ do
350 describe "Zip operations" $ do
351− prop "zipStreamly applicative" $ zipApplicative A.fromFoldable zipStreamly (==)
351+ prop "asZipStream applicative" $ zipApplicative A.fromFoldable asZipStream (==)
352 -- XXX this hangs
352 -- XXX this hangs
353− -- prop "zipParallely applicative" $ zipApplicative zipParallely (==)
353+ -- prop "asZipParallel applicative" $ zipApplicative asZipParallel (==)
354− prop "zip monadic streamly" $ zipMonadic A.fromFoldable streamly (==)
354+ prop "zip monadic asStream" $ zipMonadic A.fromFoldable asStream (==)
355− prop "zip monadic streamly folded" $ zipMonadic folded streamly (==)
355+ prop "zip monadic asStream folded" $ zipMonadic folded asStream (==)
356− prop "zip monadic costreamly" $ zipMonadic A.fromFoldable costreamly (==)
356+ prop "zip monadic asCostream" $ zipMonadic A.fromFoldable asCostream (==)
357− prop "zip monadic costreamly folded" $ zipMonadic folded costreamly (==)
357+ prop "zip monadic asCostream folded" $ zipMonadic folded asCostream (==)
358− prop "zip monadic coparallely" $ zipMonadic A.fromFoldable coparallely (==)
358+ prop "zip monadic asParAhead" $ zipMonadic A.fromFoldable asParAhead (==)
359− prop "zip monadic coparallely folded" $ zipMonadic folded coparallely (==)
359+ prop "zip monadic asParAhead folded" $ zipMonadic folded asParAhead (==)
360− prop "zip monadic parallely" $ zipMonadic A.fromFoldable parallely (==)
360+ prop "zip monadic asCoparAhead" $ zipMonadic A.fromFoldable asCoparAhead (==)
361− prop "zip monadic parallely folded" $ zipMonadic folded parallely (==)
361+ prop "zip monadic asCoparAhead folded" $ zipMonadic folded asCoparAhead (==)
362
362
363 describe "Monad operations" $ do
363 describe "Monad operations" $ do
364− prop "streamly monad then" $ monadThen A.fromFoldable streamly (==)
364+ prop "asStream monad then" $ monadThen A.fromFoldable asStream (==)
365− prop "costreamly monad then" $ monadThen A.fromFoldable costreamly sortEq
365+ prop "asCostream monad then" $ monadThen A.fromFoldable asCostream sortEq
366− prop "coparallely monad then" $ monadThen A.fromFoldable coparallely sortEq
366+ prop "asParAhead monad then" $ monadThen A.fromFoldable asParAhead sortEq
367− prop "parallely monad then" $ monadThen A.fromFoldable parallely sortEq
367+ prop "asCoparAhead monad then" $ monadThen A.fromFoldable asCoparAhead sortEq
368
368
369− prop "streamly monad then folded" $ monadThen folded streamly (==)
369+ prop "asStream monad then folded" $ monadThen folded asStream (==)
370− prop "costreamly monad then folded" $ monadThen folded costreamly sortEq
370+ prop "asCostream monad then folded" $ monadThen folded asCostream sortEq
371− prop "coparallely monad then folded" $ monadThen folded coparallely sortEq
371+ prop "asParAhead monad then folded" $ monadThen folded asParAhead sortEq
372− prop "parallely monad then folded" $ monadThen folded parallely sortEq
372+ prop "asCoparAhead monad then folded" $ monadThen folded asCoparAhead sortEq
373
373
374− prop "streamly monad bind" $ monadBind A.fromFoldable streamly (==)
374+ prop "asStream monad bind" $ monadBind A.fromFoldable asStream (==)
375− prop "costreamly monad bind" $ monadBind A.fromFoldable costreamly sortEq
375+ prop "asCostream monad bind" $ monadBind A.fromFoldable asCostream sortEq
376− prop "coparallely monad bind" $ monadBind A.fromFoldable coparallely sortEq
376+ prop "asParAhead monad bind" $ monadBind A.fromFoldable asParAhead sortEq
377− prop "parallely monad bind" $ monadBind A.fromFoldable parallely sortEq
377+ prop "asCoparAhead monad bind" $ monadBind A.fromFoldable asCoparAhead sortEq
378
378
379 describe "Stream transform operations" $ do
379 describe "Stream transform operations" $ do
380− transformOps A.fromFoldable "streamly" streamly (==)
380+ transformOps A.fromFoldable "asStream" asStream (==)
381− transformOps A.fromFoldable "costreamly" costreamly (==)
381+ transformOps A.fromFoldable "asCostream" asCostream (==)
382− transformOps A.fromFoldable "zipStreamly" zipStreamly (==)
382+ transformOps A.fromFoldable "asZipStream" asZipStream (==)
383− transformOps A.fromFoldable "zipParallely" zipParallely (==)
383+ transformOps A.fromFoldable "asZipParallel" asZipParallel (==)
384− transformOps A.fromFoldable "coparallely" coparallely sortEq
384+ transformOps A.fromFoldable "asParAhead" asParAhead sortEq
385− transformOps A.fromFoldable "parallely" parallely sortEq
385+ transformOps A.fromFoldable "asCoparAhead" asCoparAhead sortEq
386−
386+
387− transformOps folded "streamly folded" streamly (==)
387+ transformOps folded "asStream folded" asStream (==)
388− transformOps folded "costreamly folded" costreamly (==)
388+ transformOps folded "asCostream folded" asCostream (==)
389− transformOps folded "zipStreamly folded" zipStreamly (==)
389+ transformOps folded "asZipStream folded" asZipStream (==)
390− transformOps folded "zipParallely folded" zipParallely (==)
390+ transformOps folded "asZipParallel folded" asZipParallel (==)
391− transformOps folded "coparallely folded" coparallely sortEq
391+ transformOps folded "asParAhead folded" asParAhead sortEq
392− transformOps folded "parallely folded" parallely sortEq
392+ transformOps folded "asCoparAhead folded" asCoparAhead sortEq
393−
393+
394− transformOpsWord8 A.fromFoldable "streamly" streamly
394+ transformOpsWord8 A.fromFoldable "asStream" asStream
395− transformOpsWord8 A.fromFoldable "costreamly" costreamly
395+ transformOpsWord8 A.fromFoldable "asCostream" asCostream
396− transformOpsWord8 A.fromFoldable "zipStreamly" zipStreamly
396+ transformOpsWord8 A.fromFoldable "asZipStream" asZipStream
397− transformOpsWord8 A.fromFoldable "zipParallely" zipParallely
397+ transformOpsWord8 A.fromFoldable "asZipParallel" asZipParallel
398− transformOpsWord8 A.fromFoldable "coparallely" coparallely
398+ transformOpsWord8 A.fromFoldable "asParAhead" asParAhead
399− transformOpsWord8 A.fromFoldable "parallely" parallely
399+ transformOpsWord8 A.fromFoldable "asCoparAhead" asCoparAhead
400−
400+
401− transformOpsWord8 folded "streamly folded" streamly
401+ transformOpsWord8 folded "asStream folded" asStream
402− transformOpsWord8 folded "costreamly folded" costreamly
402+ transformOpsWord8 folded "asCostream folded" asCostream
403− transformOpsWord8 folded "zipStreamly folded" zipStreamly
403+ transformOpsWord8 folded "asZipStream folded" asZipStream
404− transformOpsWord8 folded "zipParallely folded" zipParallely
404+ transformOpsWord8 folded "asZipParallel folded" asZipParallel
405− transformOpsWord8 folded "coparallely folded" coparallely
405+ transformOpsWord8 folded "asParAhead folded" asParAhead
406− transformOpsWord8 folded "parallely folded" parallely
406+ transformOpsWord8 folded "asCoparAhead folded" asCoparAhead
407
407
408 describe "Stream elimination operations" $ do
408 describe "Stream elimination operations" $ do
409− eliminationOps A.fromFoldable "streamly" streamly
409+ eliminationOps A.fromFoldable "asStream" asStream
410− eliminationOps A.fromFoldable "costreamly" costreamly
410+ eliminationOps A.fromFoldable "asCostream" asCostream
411− eliminationOps A.fromFoldable "zipStreamly" zipStreamly
411+ eliminationOps A.fromFoldable "asZipStream" asZipStream
412− eliminationOps A.fromFoldable "zipParallely" zipParallely
412+ eliminationOps A.fromFoldable "asZipParallel" asZipParallel
413− eliminationOps A.fromFoldable "coparallely" coparallely
413+ eliminationOps A.fromFoldable "asParAhead" asParAhead
414− eliminationOps A.fromFoldable "parallely" parallely
414+ eliminationOps A.fromFoldable "asCoparAhead" asCoparAhead
415−
415+
416− eliminationOps folded "streamly folded" streamly
416+ eliminationOps folded "asStream folded" asStream
417− eliminationOps folded "costreamly folded" costreamly
417+ eliminationOps folded "asCostream folded" asCostream
418− eliminationOps folded "zipStreamly folded" zipStreamly
418+ eliminationOps folded "asZipStream folded" asZipStream
419− eliminationOps folded "zipParallely folded" zipParallely
419+ eliminationOps folded "asZipParallel folded" asZipParallel
420− eliminationOps folded "coparallely folded" coparallely
420+ eliminationOps folded "asParAhead folded" asParAhead
421− eliminationOps folded "parallely folded" parallely
421+ eliminationOps folded "asCoparAhead folded" asCoparAhead
422
422
423 describe "Stream elimination operations" $ do
423 describe "Stream elimination operations" $ do
424− serialEliminationOps A.fromFoldable "streamly" streamly
424+ serialEliminationOps A.fromFoldable "asStream" asStream
425− serialEliminationOps A.fromFoldable "costreamly" costreamly
425+ serialEliminationOps A.fromFoldable "asCostream" asCostream
426− serialEliminationOps A.fromFoldable "zipStreamly" zipStreamly
426+ serialEliminationOps A.fromFoldable "asZipStream" asZipStream
427− serialEliminationOps A.fromFoldable "zipParallely" zipParallely
427+ serialEliminationOps A.fromFoldable "asZipParallel" asZipParallel
428−
428+
429− serialEliminationOps folded "streamly folded" streamly
429+ serialEliminationOps folded "asStream folded" asStream
430− serialEliminationOps folded "costreamly folded" costreamly
430+ serialEliminationOps folded "asCostream folded" asCostream
431− serialEliminationOps folded "zipStreamly folded" zipStreamly
431+ serialEliminationOps folded "asZipStream folded" asZipStream
432− serialEliminationOps folded "zipParallely folded" zipParallely
432+ serialEliminationOps folded "asZipParallel folded" asZipParallel
test/loops.hs+3−3
@@ -32,7 +32,7 @@ main = do
32
32
33 putStrLn $ "\nParallel interleave:\n"
33 putStrLn $ "\nParallel interleave:\n"
34 runStream $ do
34 runStream $ do
35− x <- (return 0 <> return 1) `parallel` (return 100 <> return 101)
35+ x <- (return 0 <> return 1) `coparAhead` (return 100 <> return 101)
36 once $ print (x :: Int)
36 once $ print (x :: Int)
37
37
38 where
38 where
@@ -63,12 +63,12 @@ main = do
63 loopTailA :: Int -> Stream Int
63 loopTailA :: Int -> Stream Int
64 loopTailA x = do
64 loopTailA x = do
65 once $ putStrLn "LoopTailA..."
65 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)
67
67
68 loopHeadA :: Int -> Stream Int
68 loopHeadA :: Int -> Stream Int
69 loopHeadA x = do
69 loopHeadA x = do
70 once $ putStrLn "LoopHeadA..."
70 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
72
72
73-------------------------------------------------------------------------------
73-------------------------------------------------------------------------------
74-- Parallel (fairly scheduled, multi-threaded) stream generator loops
74-- Parallel (fairly scheduled, multi-threaded) stream generator loops
test/nested-loops.hs+1−1
@@ -21,4 +21,4 @@ main = runStream $ do
21 rnd <- once (randomIO :: IO Int)
21 rnd <- once (randomIO :: IO Int)
22 let result = (name ++ show rnd)
22 let result = (name ++ show rnd)
23 repeat = if n > 1 then loop name (n - 1) else nil
23 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
7main = do
7main = do
8 hSetBuffering stdout LineBuffering
8 hSetBuffering stdout LineBuffering
9 runStream $ do
9 runStream $ do
10− x <- S.take 10 $ loop "A" `parallel` loop "B"
10+ x <- S.take 10 $ loop "A" `coparAhead` loop "B"
11 S.once $ myThreadId >>= putStr . show
11 S.once $ myThreadId >>= putStr . show
12 >> putStr " got "
12 >> putStr " got "
13 >> print x
13 >> print x
@@ -23,4 +23,4 @@ main = do
23 S.once $ myThreadId >>= putStr . show
23 S.once $ myThreadId >>= putStr . show
24 >> putStr " yielding "
24 >> putStr " yielding "
25 >> print rnd
25 >> print rnd
26− return (name, rnd) `parallel` loop name
26+ return (name, rnd) `coparAhead` loop name