on master help sign in
Merge pull request #62 from composewell/renaming
ac7a4abHarendra Kumar
Changelog.md+29−18
@@ -9,8 +9,8 @@
9 * For `ParallelT`, the `<>` operation now concurrently meges the two streams
9 * For `ParallelT`, the `<>` operation now concurrently meges the two streams
10 in a fairly parallel manner.
10 in a fairly parallel manner.
11
11
12− To adapt to the new changes, replace `<>` with `append` wherever it is used
12+ To adapt to the new changes, replace `<>` with `serial` wherever it is used
13− for streams other than `StreamT`.
13+ for stream types other than `StreamT`.
14
14
15* Change the semantics of `Alternative` instance. The `<|>` operator now has a
15* Change the semantics of `Alternative` instance. The `<|>` operator now has a
16 different behavior for each type. See the documentation for more details. To
16 different behavior for each type. See the documentation for more details. To
@@ -19,39 +19,50 @@
19* Stream type now defaults to the `SerialT` type unless explicitly specified
19* Stream type now defaults to the `SerialT` type unless explicitly specified
20 using a type combinator or a monomorphic type. This change reduces puzzling
20 using a type combinator or a monomorphic type. This change reduces puzzling
21 type errors for beginners. It includes the following two changes:
21 type errors for beginners. It includes the following two changes:
22− * Change the type of all stream elimination functions to `SerialT`. This
22+ * Change the type of all stream elimination functions to use `SerialT`
23+ instead of a polymorphic type. This makes sure that the stream type is
23− makes sure that the stream type is always fixed at all exits.
24+ always fixed at all exits.
24− * Change the type combinators to only fix the argument stream type and
25+ * Change the type combinators (e.g. `parallely`) to only fix the argument
25− the resulting stream type remains polymorphic.
26+ stream type and the output stream type remains polymorphic.
26
27
27− Stream types may have to be changed or type combinators may have to added or
28+ Stream types may have to be changed or type combinators may have to be added
28− removed to adapt to this change.
29+ or removed to adapt to this change.
29* Change the type of `foldrM` to make it consistent with `foldrM` in base.
30* Change the type of `foldrM` to make it consistent with `foldrM` in base.
30
31
31### Deprecations
32### Deprecations
32* Deprecate and rename the following symbols:
33* Deprecate and rename the following symbols:
33− * `StreamT` to `SerialT`
34− * `runStreamT` to `runSerialT`
35− * `ZipStream` to `ZipSerial`
36− * `runZipStream` to `runZipSerial`
37− * `AsyncT` to `AParallelT`
38− * `runAsyncT` to `runAParallelT`
39− * `asyncly` to `aparallely`
40 * `Streaming` to `IsStream`
34 * `Streaming` to `IsStream`
41 * `runStreaming` to `runStream`
35 * `runStreaming` to `runStream`
42− * `<=>` to `interleave`
36+ * `StreamT` to `SerialT`
43− * `<|` to `aparallel`
37+ * `AsyncT` to `CoparallelT`
38+ * `ZipStream` to `ZipSerial`
39+ * `ZipAsync` to `ZipParallel`
40+ * `interleaving` to `coserially`
41+ * `asyncly` to `coparallely`
42+ * `zipping` to `zipSerially`
43+ * `zippingAsync` to `zipParallely`
44+ * `<=>` to `coserial`
45+ * `<|` to `coparallel`
44 * `each` to `fromFoldable`
46 * `each` to `fromFoldable`
45 * `scan` to `scanx`
47 * `scan` to `scanx`
46 * `foldl` to `foldx`
48 * `foldl` to `foldx`
47 * `foldlM` to `foldxM`
49 * `foldlM` to `foldxM`
50+ * `zipAsyncWith` to `zipParallelWith`
51+ * `zipAsyncWithM` to `zipParallelWithM`
52+* Deprecate and remove the following symbols:
53+ * `runStreamT`
54+ * `runInterleavedT`
55+ * `runAsyncT`
56+ * `runParallelT`
57+ * `runZipStream`
58+ * `runZipAsync`
48
59
49### Enhancements
60### Enhancements
50* Add the following functions:
61* Add the following functions:
51 * `scanl'` strict left scan
62 * `scanl'` strict left scan
52 * `foldl'` strict left fold
63 * `foldl'` strict left fold
53 * `foldlM'` strict left fold with a monadic fold function
64 * `foldlM'` strict left fold with a monadic fold function
54− * `append` run two streams serially one after the other
65+ * `serial` run two streams serially one after the other
55 * `parallel` run two streams in parallel (replaces `<|>`)
66 * `parallel` run two streams in parallel (replaces `<|>`)
56
67
57## 0.1.2
68## 0.1.2
benchmark/Main.hs+19−19
@@ -41,38 +41,38 @@ main = do
41 [ bench "function style all serial" $ nfIO streamly_function_style
41 [ bench "function style all serial" $ nfIO streamly_function_style
42
42
43 , bgroup "serial bind"
43 , bgroup "serial bind"
44− [ bench "serial" $ nfIO (as (A.append))
44+ [ bench "serial" $ nfIO (as (A.serial))
45− , bench "fair serial" $ nfIO (as (A.interleave))
45+ , bench "fair serial" $ nfIO (as (A.coserial))
46− , bench "left parallel" $ nfIO (as (A.aparallel))
46+ , bench "left parallel" $ nfIO (as (A.coparallel))
47 , bench "fair parallel" $ nfIO (as (A.parallel))
47 , bench "fair parallel" $ nfIO (as (A.parallel))
48 ]
48 ]
49
49
50 , bgroup "interleaved bind"
50 , bgroup "interleaved bind"
51− [ bench "serial" $ nfIO (ai (A.append))
51+ [ bench "serial" $ nfIO (ai (A.serial))
52− , bench "fair serial" $ nfIO (ai (A.interleave))
52+ , bench "fair serial" $ nfIO (ai (A.coserial))
53− , bench "left parallel" $ nfIO (ai (A.aparallel))
53+ , bench "left parallel" $ nfIO (ai (A.coparallel))
54 , bench "fair parallel" $ nfIO (ai (A.parallel))
54 , bench "fair parallel" $ nfIO (ai (A.parallel))
55 ]
55 ]
56
56
57 , bgroup "async bind"
57 , bgroup "async bind"
58− [ bench "serial" $ nfIO (aa (A.append))
58+ [ bench "serial" $ nfIO (aa (A.serial))
59− , bench "fair serial" $ nfIO (aa (A.interleave))
59+ , bench "fair serial" $ nfIO (aa (A.coserial))
60− , bench "left parallel" $ nfIO (aa (A.aparallel))
60+ , bench "left parallel" $ nfIO (aa (A.coparallel))
61 , bench "fair parallel" $ nfIO (aa (A.parallel))
61 , bench "fair parallel" $ nfIO (aa (A.parallel))
62 ]
62 ]
63
63
64 , bgroup "parallel bind"
64 , bgroup "parallel bind"
65− [ bench "serial" $ nfIO (ap (A.append))
65+ [ bench "serial" $ nfIO (ap (A.serial))
66− , bench "fair serial" $ nfIO (ap (A.interleave))
66+ , bench "fair serial" $ nfIO (ap (A.coserial))
67− , bench "left parallel" $ nfIO (ap (A.aparallel))
67+ , bench "left parallel" $ nfIO (ap (A.coparallel))
68 , bench "fair parallel" $ nfIO (ap (A.parallel))
68 , bench "fair parallel" $ nfIO (ap (A.parallel))
69 ]
69 ]
70
70
71 -- Benchmark smallest possible actions composed together
71 -- Benchmark smallest possible actions composed together
72 , bgroup "serial bind nil"
72 , bgroup "serial bind nil"
73− [ bench "serial" $ nfIO (streamly_nil (A.append))
73+ [ bench "serial" $ nfIO (streamly_nil (A.serial))
74− , bench "fair serial" $ nfIO (streamly_nil (A.interleave))
74+ , bench "fair serial" $ nfIO (streamly_nil (A.coserial))
75− , bench "left parallel" $ nfIO (streamly_nil (A.aparallel))
75+ , bench "left parallel" $ nfIO (streamly_nil (A.coparallel))
76 , bench "fair parallel" $ nfIO (streamly_nil (A.parallel))
76 , bench "fair parallel" $ nfIO (streamly_nil (A.parallel))
77 ]
77 ]
78 ]
78 ]
@@ -141,15 +141,15 @@ streamly_serial = streamly_basic (A.toList . A.serially)
141
141
142{-# INLINE streamly_interleaved #-}
142{-# INLINE streamly_interleaved #-}
143streamly_interleaved
143streamly_interleaved
144− :: (A.InterleavedT IO Int -> A.InterleavedT IO Int -> A.InterleavedT IO Int)
144+ :: (A.CoserialT IO Int -> A.CoserialT IO Int -> A.CoserialT IO Int)
145 -> IO Int
145 -> IO Int
146−streamly_interleaved = streamly_basic (A.toList . A.interleaving)
146+streamly_interleaved = streamly_basic (A.toList . A.coserially)
147
147
148{-# INLINE streamly_async #-}
148{-# INLINE streamly_async #-}
149streamly_async
149streamly_async
150− :: (A.AParallelT IO Int -> A.AParallelT IO Int -> A.AParallelT IO Int)
150+ :: (A.CoparallelT IO Int -> A.CoparallelT IO Int -> A.CoparallelT IO Int)
151 -> IO Int
151 -> IO Int
152−streamly_async = streamly_basic (A.toList . A.aparallely)
152+streamly_async = streamly_basic (A.toList . A.coparallely)
153
153
154{-# INLINE streamly_parallel #-}
154{-# INLINE streamly_parallel #-}
155streamly_parallel
155streamly_parallel
examples/loops.hs+4−4
@@ -24,9 +24,9 @@ main = do
24 x <- loopHeadA 0
24 x <- loopHeadA 0
25 liftIO $ print (x :: Int)
25 liftIO $ print (x :: Int)
26
26
27− putStrLn $ "\ninterleave:\n"
27+ putStrLn $ "\ncoserial:\n"
28 runStream $ do
28 runStream $ do
29− x <- (return 0 <> return 1) `interleave` (return 100 <> return 101)
29+ x <- (return 0 <> return 1) `coserial` (return 100 <> return 101)
30 liftIO $ print (x :: Int)
30 liftIO $ print (x :: Int)
31
31
32 putStrLn $ "\nParallel interleave:\n"
32 putStrLn $ "\nParallel interleave:\n"
@@ -71,12 +71,12 @@ main = do
71 loopTailA :: Int -> SerialT IO Int
71 loopTailA :: Int -> SerialT IO Int
72 loopTailA x = do
72 loopTailA x = do
73 liftIO $ putStrLn "LoopTailA..."
73 liftIO $ putStrLn "LoopTailA..."
74− return x `aparallel` (if x < 3 then loopTailA (x + 1) else empty)
74+ return x `coparallel` (if x < 3 then loopTailA (x + 1) else empty)
75
75
76 loopHeadA :: Int -> SerialT IO Int
76 loopHeadA :: Int -> SerialT IO Int
77 loopHeadA x = do
77 loopHeadA x = do
78 liftIO $ putStrLn "LoopHeadA..."
78 liftIO $ putStrLn "LoopHeadA..."
79− (if x < 3 then loopHeadA (x + 1) else empty) `aparallel` return x
79+ (if x < 3 then loopHeadA (x + 1) else empty) `coparallel` return x
80
80
81-------------------------------------------------------------------------------
81-------------------------------------------------------------------------------
82-- Parallel (fairly scheduled, multi-threaded) stream generator loops
82-- Parallel (fairly scheduled, multi-threaded) stream generator loops
src/Streamly.hs+64−42
@@ -15,45 +15,48 @@ module Streamly
15 -- * Overview
15 -- * Overview
16 -- $overview
16 -- $overview
17
17
18− MonadAsync
18+ MonadParallel
19 , IsStream
19 , IsStream
20
20
21− -- * General Stream Styles
21+ -- * Serial Streams
22− -- $product
22+ -- $serial
23 , SerialT
23 , SerialT
24− , InterleavedT
24+ , CoserialT
25− , AParallelT
25+
26+ -- * Parallel Streams
27+ -- $parallel
28+ , CoparallelT
26 , ParallelT
29 , ParallelT
27
30
28− -- * Zip Style Streams
31+ -- * Zipping Streams
29 -- $zipping
32 -- $zipping
30 , ZipSerial
33 , ZipSerial
31− , ZipAsync
34+ , ZipParallel
32−
33− -- * Polymorphic Sum Operations
34− -- $sum
35− , append
36− , interleave
37− , aparallel
38− , parallel
39−
40− -- * Transformation
41− , async
42
35
43 -- * Stream Type Adapters
36 -- * Stream Type Adapters
44 -- $adapters
37 -- $adapters
45 , serially
38 , serially
46− , interleaving
39+ , coserially
47− , aparallely
40+ , coparallely
48 , parallely
41 , parallely
49− , zipping
42+ , zipSerially
50− , zippingAsync
43+ , zipParallely
51 , adapt
44 , adapt
52
45
53 -- * Running Streams
46 -- * Running Streams
54 , runStream
47 , runStream
55
48
49+ -- * Transformation
50+ , async
51+
52+ -- * Polymorphic Sum Operations
53+ -- $sum
54+ , serial
55+ , coserial
56+ , coparallel
57+ , parallel
58+
56− -- * Fold Utilities
59+ -- * Polymorphic Fold Utilities
57 -- $foldutils
60 -- $foldutils
58 , foldWith
61 , foldWith
59 , foldMapWith
62 , foldMapWith
@@ -68,6 +71,7 @@ module Streamly
68 , MonadTrans (..)
71 , MonadTrans (..)
69
72
70 -- * Deprecated
73 -- * Deprecated
74+ , MonadAsync
71 , Streaming
75 , Streaming
72 , runStreaming
76 , runStreaming
73 , runStreamT
77 , runStreamT
@@ -77,9 +81,14 @@ module Streamly
77 , runAsyncT
81 , runAsyncT
78 , runZipStream
82 , runZipStream
79 , StreamT
83 , StreamT
84+ , InterleavedT
80 , AsyncT
85 , AsyncT
81 , ZipStream
86 , ZipStream
87+ , ZipAsync
88+ , interleaving
82 , asyncly
89 , asyncly
90+ , zipping
91+ , zippingAsync
83 , (<=>)
92 , (<=>)
84 , (<|)
93 , (<|)
85 )
94 )
@@ -126,28 +135,28 @@ import Control.Monad.Trans.Class (MonadTrans (..))
126
135
127-- $overview
136-- $overview
128--
137--
129−-- Streamly provides six distinct stream types i.e. 'SerialT', 'InterleavedT',
138+-- Streamly provides six distinct stream types i.e. 'SerialT', 'CoserialT',
130−-- 'AParallelT' and 'ParallelT', 'ZipStream' and 'ZipAsync', each representing a
139+-- 'CoparallelT' and 'ParallelT', 'ZipSerial' and 'ZipParallel', each representing a
131-- stream of elements. All these types have the same underlying representation
140-- stream of elements. All these types have the same underlying representation
132-- and can be adapted from one to another using type adaptor combinators
141-- and can be adapted from one to another using type adaptor combinators
133-- described later. Each of these types belongs to the 'IsStream' type class
142-- described later. Each of these types belongs to the 'IsStream' type class
134-- which helps converting the specific type to and from the underlying generic
143-- which helps converting the specific type to and from the underlying generic
135-- stream type.
144-- stream type.
136--
145--
137−-- The types 'SerialT', 'InterleavedT', 'AParallelT' and 'ParallelT' are 'Monad'
146+-- The types 'SerialT', 'CoserialT', 'CoparallelT' and 'ParallelT' are 'Monad'
138-- transformers with the monadic bind operation combining streams in a product
147-- transformers with the monadic bind operation combining streams in a product
139-- style in much the same way as a list monad or a list transformer i.e. each
148-- style in much the same way as a list monad or a list transformer i.e. each
140-- element from one stream is combined with every element of the other stream.
149-- element from one stream is combined with every element of the other stream.
141-- However, the applicative and monadic composition of these types differ in
150-- However, the applicative and monadic composition of these types differ in
142-- terms of the ordering and time sequence in which the elements from two
151-- terms of the ordering and time sequence in which the elements from two
143−-- streams are combined. 'SerialT' and 'InterleavedT' compose streams serially
152+-- streams are combined. 'SerialT' and 'CoserialT' compose streams serially
144−-- whereas 'AParallelT' and 'ParallelT' are their concurrent counterparts. See the
153+-- whereas 'CoparallelT' and 'ParallelT' are their concurrent counterparts. See the
145-- documentation of the respective types for more details.
154-- documentation of the respective types for more details.
146--
155--
147−-- The types 'ZipStream' and 'ZipAsync' provide 'Applicative' instances to zip
156+-- The types 'ZipSerial' and 'ZipParallel' provide 'Applicative' instances to zip
148-- two streams together i.e. each element in one stream is combined with the
157-- two streams together i.e. each element in one stream is combined with the
149−-- corresponding element in the other stream. 'ZipStream' generates the streams
158+-- corresponding element in the other stream. 'ZipSerial' generates the streams
150−-- being zipped serially whereas 'ZipAsync' produces both the elements being
159+-- being zipped serially whereas 'ZipParallel' produces both the elements being
151-- zipped concurrently.
160-- zipped concurrently.
152--
161--
153-- Two streams of the same type can be merged using a sum style composition to
162-- Two streams of the same type can be merged using a sum style composition to
@@ -156,25 +165,37 @@ import Control.Monad.Trans.Class (MonadTrans (..))
156-- (concurrent or serial) in which the elements in the resulting stream are
165-- (concurrent or serial) in which the elements in the resulting stream are
157-- produced depends on the type of the stream.
166-- produced depends on the type of the stream.
158--
167--
159−-- Concurrent composition types 'AParallelT', 'ParallelT', 'ZipAsync' require the
160−-- underlying monad of the streaming monad transformer to be 'MonadAsync'.
161−--
162-- For more details please see the "Streamly.Tutorial" and "Streamly.Examples"
168-- For more details please see the "Streamly.Tutorial" and "Streamly.Examples"
163-- (the latter is available only when built with the 'examples' build flag).
169-- (the latter is available only when built with the 'examples' build flag).
164
170
165-- A simple inline example here illustrating applicative, monad and alternative
171-- A simple inline example here illustrating applicative, monad and alternative
166-- compositions.
172-- compositions.
167
173
168−-- $product
174+-- $serial
175+--
176+-- Serial streams compose serially or non-concurrently. In a composed stream,
177+-- at any point of time only one constituent stream runs and yields an element.
178+-- The two serial stream types 'SerialT' and 'CoserialT' differ in how they
179+-- merge streams together in a 'Semigroup' or 'Monad' composition. As these
180+-- streams are serial, the sequence of items in a composed stream can be solely
181+-- determined by the position of elements in the consituent streams.
182+
183+-- $parallel
169--
184--
170−-- Streams that compose serially or non-concurrently come in two flavors i.e.
185+-- Parallel streams compose parallely or concurrently. In a composed stream, at
171−-- 'SerialT' and 'InterleavedT'. Both of these serial flavors have
186+-- any point of time more than one stream can run concurrently and yield
172−-- corresponding concurrent equivalents, those are 'AParallelT' and 'ParallelT'
187+-- elements. The two parallel types 'ParallelT' and 'CoparallelT' differ in how
173−-- respectively.
188+-- they merge streams together in a 'Semigroup' or 'Monad' composition. As
189+-- these streams compose concurrently, the sequence of items in a composed
190+-- stream cannot be determined by the position of elements in the constituent
191+-- streams. The elements are yielded by the composed stream as they are
192+-- generated by the constituent streams on a first come first serve basis.
193+-- Therefore, on each run the stream may yield elements in a different sequence
194+-- depending on the delays introduced by scheduling.
174
195
175-- $zipping
196-- $zipping
176--
197--
177−-- 'ZipStream' and 'ZipAsync', provide 'Applicative' instances for zipping the
198+-- 'ZipSerial' and 'ZipParallel', provide 'Applicative' instances for zipping the
178-- corresponding elements of two streams together. Note that these types are
199-- corresponding elements of two streams together. Note that these types are
179-- not monads.
200-- not monads.
180
201
@@ -193,7 +214,7 @@ import Control.Monad.Trans.Class (MonadTrans (..))
193-- To adapt from one monomorphic type (e.g. 'ParallelT') to another monomorphic
214-- To adapt from one monomorphic type (e.g. 'ParallelT') to another monomorphic
194-- type (e.g. 'SerialT') use the 'adapt' combinator. To give a polymorphic code
215-- type (e.g. 'SerialT') use the 'adapt' combinator. To give a polymorphic code
195-- a specific interpretation or to adapt a specific type to a polymorphic type
216-- a specific interpretation or to adapt a specific type to a polymorphic type
196−-- use the type specific combinators e.g. 'parallely' or 'interleaving'. You
217+-- use the type specific combinators e.g. 'parallely' or 'coserially'. You
197-- cannot adapt polymorphic code to polymorphic code, as it would not know
218-- cannot adapt polymorphic code to polymorphic code, as it would not know
198-- which specific type you are converting from or to. If you see a an
219-- which specific type you are converting from or to. If you see a an
199-- @ambiguous type variable@ error then most likely you are using 'adapt'
220-- @ambiguous type variable@ error then most likely you are using 'adapt'
@@ -202,5 +223,6 @@ import Control.Monad.Trans.Class (MonadTrans (..))
202
223
203-- $foldutils
224-- $foldutils
204--
225--
205−-- These are some convenience functions to fold any 'Foldable' container using
226+-- These are variants of standard 'Foldable' fold functions that use a
206−-- one of the sum composition operators to convert it into a streamly stream.
227+-- polymorphic stream sum operation (e.g. 'parallel' or 'coserial') to fold a
228+-- container of streams.
src/Streamly/Core.hs+32−28
@@ -18,7 +18,8 @@
18--
18--
19module Streamly.Core
19module Streamly.Core
20 (
20 (
21+ MonadParallel
21− MonadAsync
22+ , MonadAsync -- deprecated
22
23
23 -- * Streams
24 -- * Streams
24 , Stream (..)
25 , Stream (..)
@@ -29,9 +30,9 @@ module Streamly.Core
29 , nil
30 , nil
30
31
31 -- * Semigroup Style Composition
32 -- * Semigroup Style Composition
32− , append
33+ , serial
33− , interleave
34+ , coserial
34− , aparallel
35+ , coparallel
35 , parallel
36 , parallel
36
37
37 -- * Alternative
38 -- * Alternative
@@ -213,10 +214,13 @@ newtype Stream m a =
213 -> m r
214 -> m r
214 }
215 }
215
216
216−-- | A monad that can perform asynchronous/concurrent IO operations. Streams
217+-- | A monad that can perform concurrent or parallel IO operations. Streams
217-- that can be composed concurrently require the underlying monad to be
218-- that can be composed concurrently require the underlying monad to be
218−-- 'MonadAsync'.
219+-- 'MonadParallel'.
219−type MonadAsync m = (MonadIO m, MonadBaseControl IO m, MonadThrow m)
220+type MonadParallel m = (MonadIO m, MonadBaseControl IO m, MonadThrow m)
221+
222+{-# DEPRECATED MonadAsync "Please use MonadParallel instead." #-}
223+type MonadAsync m = MonadParallel m
220
224
221cons :: a -> Maybe (Stream m a) -> Stream m a
225cons :: a -> Maybe (Stream m a) -> Stream m a
222cons a r = Stream $ \_ _ yld -> yld a r
226cons a r = Stream $ \_ _ yld -> yld a r
@@ -242,8 +246,8 @@ nil = Stream $ \_ stp _ -> stp
242
246
243-- | Concatenates two streams sequentially i.e. the first stream is
247-- | Concatenates two streams sequentially i.e. the first stream is
244-- exhausted completely before yielding any element from the second stream.
248-- exhausted completely before yielding any element from the second stream.
245−append :: Stream m a -> Stream m a -> Stream m a
249+serial :: Stream m a -> Stream m a -> Stream m a
246−append m1 m2 = go m1
250+serial m1 m2 = go m1
247 where
251 where
248 go (Stream m) = Stream $ \_ stp yld ->
252 go (Stream m) = Stream $ \_ stp yld ->
249 let stop = (runStream m2) Nothing stp yld
253 let stop = (runStream m2) Nothing stp yld
@@ -252,7 +256,7 @@ append m1 m2 = go m1
252 in m Nothing stop yield
256 in m Nothing stop yield
253
257
254instance Semigroup (Stream m a) where
258instance Semigroup (Stream m a) where
255− (<>) = append
259+ (<>) = serial
256
260
257------------------------------------------------------------------------------
261------------------------------------------------------------------------------
258-- Monoid
262-- Monoid
@@ -266,11 +270,11 @@ instance Monoid (Stream m a) where
266-- Interleave
270-- Interleave
267------------------------------------------------------------------------------
271------------------------------------------------------------------------------
268
272
269−interleave :: Stream m a -> Stream m a -> Stream m a
273+coserial :: Stream m a -> Stream m a -> Stream m a
270−interleave m1 m2 = Stream $ \_ stp yld -> do
274+coserial m1 m2 = Stream $ \_ stp yld -> do
271 let stop = (runStream m2) Nothing stp yld
275 let stop = (runStream m2) Nothing stp yld
272 yield a Nothing = yld a (Just m2)
276 yield a Nothing = yld a (Just m2)
273− yield a (Just r) = yld a (Just (interleave m2 r))
277+ yield a (Just r) = yld a (Just (coserial m2 r))
274 (runStream m1) Nothing stop yield
278 (runStream m1) Nothing stop yield
275
279
276------------------------------------------------------------------------------
280------------------------------------------------------------------------------
@@ -377,7 +381,7 @@ handleChildException sv e = do
377 send sv (ChildStop tid (Just e))
381 send sv (ChildStop tid (Just e))
378
382
379{-# NOINLINE pushWorker #-}
383{-# NOINLINE pushWorker #-}
380−pushWorker :: MonadAsync m => SVar m a -> m ()
384+pushWorker :: MonadParallel m => SVar m a -> m ()
381pushWorker sv =
385pushWorker sv =
382 doFork (runqueue sv) (handleChildException sv) >>= addThread sv
386 doFork (runqueue sv) (handleChildException sv) >>= addThread sv
383
387
@@ -386,7 +390,7 @@ pushWorker sv =
386-- block or make it go away entirely, depending on the number of workers and
390-- block or make it go away entirely, depending on the number of workers and
387-- the type of the queue.
391-- the type of the queue.
388{-# INLINE sendWorkerWait #-}
392{-# INLINE sendWorkerWait #-}
389−sendWorkerWait :: MonadAsync m => SVar m a -> m ()
393+sendWorkerWait :: MonadParallel m => SVar m a -> m ()
390sendWorkerWait sv = do
394sendWorkerWait sv = do
391 case svarStyle sv of
395 case svarStyle sv of
392 SVarStyle _ LIFO -> liftIO $ threadDelay 200
396 SVarStyle _ LIFO -> liftIO $ threadDelay 200
@@ -401,7 +405,7 @@ sendWorkerWait sv = do
401
405
402-- | Pull a stream from an SVar.
406-- | Pull a stream from an SVar.
403{-# NOINLINE fromStreamVar #-}
407{-# NOINLINE fromStreamVar #-}
404−fromStreamVar :: MonadAsync m => SVar m a -> Stream m a
408+fromStreamVar :: MonadParallel m => SVar m a -> Stream m a
405fromStreamVar sv = Stream $ \_ stp yld -> do
409fromStreamVar sv = Stream $ \_ stp yld -> do
406 -- XXX if reading the IORef is costly we can use a flag in the SVar to
410 -- XXX if reading the IORef is costly we can use a flag in the SVar to
407 -- indicate we are done.
411 -- indicate we are done.
@@ -479,7 +483,7 @@ getLifoSVar ctype = do
479 in return sv
483 in return sv
480
484
481-- | Create a new empty SVar.
485-- | Create a new empty SVar.
482−newEmptySVar :: MonadAsync m => SVarStyle -> m (SVar m a)
486+newEmptySVar :: MonadParallel m => SVarStyle -> m (SVar m a)
483newEmptySVar style = do
487newEmptySVar style = do
484 liftIO $
488 liftIO $
485 case style of
489 case style of
@@ -487,7 +491,7 @@ newEmptySVar style = do
487 SVarStyle _ LIFO -> getLifoSVar style
491 SVarStyle _ LIFO -> getLifoSVar style
488
492
489-- | Create a new SVar and enqueue one stream computation on it.
493-- | Create a new SVar and enqueue one stream computation on it.
490−newStreamVar1 :: MonadAsync m => SVarStyle -> Stream m a -> m (SVar m a)
494+newStreamVar1 :: MonadParallel m => SVarStyle -> Stream m a -> m (SVar m a)
491newStreamVar1 style m = do
495newStreamVar1 style m = do
492 sv <- newEmptySVar style
496 sv <- newEmptySVar style
493 -- Note: We must have all the work on the queue before sending the
497 -- Note: We must have all the work on the queue before sending the
@@ -498,7 +502,7 @@ newStreamVar1 style m = do
498 return sv
502 return sv
499
503
500-- | Create a new SVar and enqueue two stream computations on it.
504-- | Create a new SVar and enqueue two stream computations on it.
501−newStreamVar2 :: MonadAsync m
505+newStreamVar2 :: MonadParallel m
502 => SVarStyle -> Stream m a -> Stream m a -> m (SVar m a)
506 => SVarStyle -> Stream m a -> Stream m a -> m (SVar m a)
503newStreamVar2 style m1 m2 = do
507newStreamVar2 style m1 m2 = do
504 -- Note: We must have all the work on the queue before sending the
508 -- Note: We must have all the work on the queue before sending the
@@ -519,7 +523,7 @@ newStreamVar2 style m1 m2 = do
519
523
520-- | Write a stream to an 'SVar' in a non-blocking manner. The stream can then
524-- | Write a stream to an 'SVar' in a non-blocking manner. The stream can then
521-- be read back from the SVar using 'fromSVar'.
525-- be read back from the SVar using 'fromSVar'.
522−toStreamVar :: MonadAsync m => SVar m a -> Stream m a -> m ()
526+toStreamVar :: MonadParallel m => SVar m a -> Stream m a -> m ()
523toStreamVar sv m = do
527toStreamVar sv m = do
524 liftIO $ (enqueue sv) m
528 liftIO $ (enqueue sv) m
525 done <- allThreadsDone sv
529 done <- allThreadsDone sv
@@ -561,7 +565,7 @@ toStreamVar sv m = do
561-- just the number of CPUs.
565-- just the number of CPUs.
562
566
563{-# NOINLINE withNewSVar2 #-}
567{-# NOINLINE withNewSVar2 #-}
564−withNewSVar2 :: MonadAsync m
568+withNewSVar2 :: MonadParallel m
565 => SVarStyle -> Stream m a -> Stream m a -> Stream m a
569 => SVarStyle -> Stream m a -> Stream m a -> Stream m a
566withNewSVar2 style m1 m2 = Stream $ \_ stp yld -> do
570withNewSVar2 style m1 m2 = Stream $ \_ stp yld -> do
567 sv <- newStreamVar2 style m1 m2
571 sv <- newStreamVar2 style m1 m2
@@ -596,7 +600,7 @@ withNewSVar2 style m1 m2 = Stream $ \_ stp yld -> do
596-- of the two.
600-- of the two.
597--
601--
598{-# INLINE joinStreamVar2 #-}
602{-# INLINE joinStreamVar2 #-}
599−joinStreamVar2 :: MonadAsync m
603+joinStreamVar2 :: MonadParallel m
600 => SVarStyle -> Stream m a -> Stream m a -> Stream m a
604 => SVarStyle -> Stream m a -> Stream m a -> Stream m a
601joinStreamVar2 style m1 m2 = Stream $ \st stp yld ->
605joinStreamVar2 style m1 m2 = Stream $ \st stp yld ->
602 case st of
606 case st of
@@ -608,12 +612,12 @@ joinStreamVar2 style m1 m2 = Stream $ \st stp yld ->
608-- Semigroup and Monoid style compositions for parallel actions
612-- Semigroup and Monoid style compositions for parallel actions
609------------------------------------------------------------------------------
613------------------------------------------------------------------------------
610
614
611−{-# INLINE aparallel #-}
615+{-# INLINE coparallel #-}
612−aparallel :: MonadAsync m => Stream m a -> Stream m a -> Stream m a
616+coparallel :: MonadParallel m => Stream m a -> Stream m a -> Stream m a
613−aparallel = joinStreamVar2 (SVarStyle Disjunction LIFO)
617+coparallel = joinStreamVar2 (SVarStyle Disjunction LIFO)
614
618
615{-# INLINE parallel #-}
619{-# INLINE parallel #-}
616−parallel :: MonadAsync m => Stream m a -> Stream m a -> Stream m a
620+parallel :: MonadParallel m => Stream m a -> Stream m a -> Stream m a
617parallel = joinStreamVar2 (SVarStyle Disjunction FIFO)
621parallel = joinStreamVar2 (SVarStyle Disjunction FIFO)
618
622
619-------------------------------------------------------------------------------
623-------------------------------------------------------------------------------
@@ -647,11 +651,11 @@ alt m1 m2 = Stream $ \_ stp yld ->
647 yield = yld
651 yield = yld
648 in runStream m1 Nothing stop yield
652 in runStream m1 Nothing stop yield
649
653
650−instance MonadAsync m => Alternative (Stream m) where
654+instance MonadParallel m => Alternative (Stream m) where
651 empty = nil
655 empty = nil
652 (<|>) = alt
656 (<|>) = alt
653
657
654−instance MonadAsync m => MonadPlus (Stream m) where
658+instance MonadParallel m => MonadPlus (Stream m) where
655 mzero = nil
659 mzero = nil
656 mplus = (<|>)
660 mplus = (<|>)
657
661
src/Streamly/Examples/AcidRainGame.hs+1−1
@@ -26,7 +26,7 @@ userAction = cycle1 $ liftIO askUser
26acidRain :: MonadIO m => SerialT m Event
26acidRain :: MonadIO m => SerialT m Event
27acidRain = cycle1 $ liftIO (threadDelay 1000000) >> return (Harm 1)
27acidRain = cycle1 $ liftIO (threadDelay 1000000) >> return (Harm 1)
28
28
29−game :: (MonadAsync m, MonadState Int m) => SerialT m ()
29+game :: (MonadParallel m, MonadState Int m) => SerialT m ()
30game = do
30game = do
31 event <- userAction `parallel` acidRain
31 event <- userAction `parallel` acidRain
32 case event of
32 case event of
src/Streamly/Examples/ListDirRecursive.hs+3−3
@@ -3,15 +3,15 @@ module Streamly.Examples.ListDirRecursive where
3import Control.Monad.IO.Class (liftIO)
3import Control.Monad.IO.Class (liftIO)
4import Path.IO (listDir, getCurrentDir)
4import Path.IO (listDir, getCurrentDir)
5import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
5import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
6−import Streamly (runStream, aparallely)
6+import Streamly (runStream, coparallely)
7
7
8-- | This example demonstrates that there is little difference between regular
8-- | This example demonstrates that there is little difference between regular
9-- IO code and concurrent streamly code. You can just remove
9-- IO code and concurrent streamly code. You can just remove
10−-- 'runStream . aparallely' and this becomes your regular IO code.
10+-- 'runStream . coparallely' and this becomes your regular IO code.
11listDirRecursive :: IO ()
11listDirRecursive :: IO ()
12listDirRecursive = do
12listDirRecursive = do
13 hSetBuffering stdout LineBuffering
13 hSetBuffering stdout LineBuffering
14− runStream . aparallely $ getCurrentDir >>= readdir
14+ runStream . coparallely $ getCurrentDir >>= readdir
15 where readdir d = do
15 where readdir d = do
16 (ds, fs) <- liftIO $ listDir d
16 (ds, fs) <- liftIO $ listDir d
17 liftIO $ mapM_ putStrLn $ map show fs ++ map show ds
17 liftIO $ mapM_ putStrLn $ map show fs ++ map show ds
src/Streamly/Examples/MergeSortedStreams.hs+2−2
@@ -14,14 +14,14 @@ getSorted = do
14 let ls = take 100000 (randoms g) :: [Word16]
14 let ls = take 100000 (randoms g) :: [Word16]
15 foldMapWith (<>) return (sort ls)
15 foldMapWith (<>) return (sort ls)
16
16
17−mergeAsync :: (Ord a, MonadAsync m)
17+mergeAsync :: (Ord a, MonadParallel m)
18 => SerialT m a -> SerialT m a -> SerialT m a
18 => SerialT m a -> SerialT m a -> SerialT m a
19mergeAsync a b = do
19mergeAsync a b = do
20 x <- lift $ async a
20 x <- lift $ async a
21 y <- lift $ async b
21 y <- lift $ async b
22 merge x y
22 merge x y
23
23
24−merge :: (Ord a, MonadAsync m) => SerialT m a -> SerialT m a -> SerialT m a
24+merge :: (Ord a, MonadParallel m) => SerialT m a -> SerialT m a -> SerialT m a
25merge a b = do
25merge a b = do
26 a1 <- lift $ A.uncons a
26 a1 <- lift $ A.uncons a
27 case a1 of
27 case a1 of
src/Streamly/Examples/SearchEngineQuery.hs+1−1
@@ -10,7 +10,7 @@ searchEngineQuery = do
10 runStream . parallely $ google <> bing <> duckduckgo
10 runStream . parallely $ google <> bing <> duckduckgo
11
11
12 putStrLn "\nUsing parallel applicative zip"
12 putStrLn "\nUsing parallel applicative zip"
13− runStream . zippingAsync $ (,,) <$> google <*> bing <*> duckduckgo
13+ runStream . zipParallely $ (,,) <$> google <*> bing <*> duckduckgo
14
14
15 where
15 where
16 get :: IsStream t => String -> t IO ()
16 get :: IsStream t => String -> t IO ()
src/Streamly/Prelude.hs+11−4
@@ -72,8 +72,8 @@ module Streamly.Prelude
72 -- * Zipping
72 -- * Zipping
73 , zipWith
73 , zipWith
74 , zipWithM
74 , zipWithM
75− , zipAsyncWith
75+ , zipParallelWith
76− , zipAsyncWithM
76+ , zipParallelWithM
77
77
78 -- * IO
78 -- * IO
79 , fromHandle
79 , fromHandle
@@ -84,6 +84,8 @@ module Streamly.Prelude
84 , scan
84 , scan
85 , foldl
85 , foldl
86 , foldlM
86 , foldlM
87+ , zipAsyncWith
88+ , zipAsyncWithM
87 )
89 )
88where
90where
89
91
@@ -569,9 +571,14 @@ zipWithM f m1 m2 = fromStream $ go (toStream m1) (toStream m2)
569
571
570-- | Zip two streams asyncly (i.e. both the elements being zipped are generated
572-- | Zip two streams asyncly (i.e. both the elements being zipped are generated
571-- concurrently) using a monadic zipping function.
573-- concurrently) using a monadic zipping function.
572−zipAsyncWithM :: (IsStream t, MonadAsync m)
574+zipParallelWithM :: (IsStream t, MonadParallel m)
573 => (a -> b -> t m c) -> t m a -> t m b -> t m c
575 => (a -> b -> t m c) -> t m a -> t m b -> t m c
574−zipAsyncWithM f m1 m2 = fromStream $ Stream $ \_ stp yld -> do
576+zipParallelWithM f m1 m2 = fromStream $ Stream $ \_ stp yld -> do
575 ma <- async m1
577 ma <- async m1
576 mb <- async m2
578 mb <- async m2
577 (S.runStream (toStream (zipWithM f ma mb))) Nothing stp yld
579 (S.runStream (toStream (zipWithM f ma mb))) Nothing stp yld
580+
581+{-# DEPRECATED zipAsyncWithM "Please use zipParallelWithM instead." #-}
582+zipAsyncWithM :: (IsStream t, MonadParallel m)
583+ => (a -> b -> t m c) -> t m a -> t m b -> t m c
584+zipAsyncWithM = zipParallelWithM
src/Streamly/Streams.hs+198−170
@@ -21,7 +21,8 @@ module Streamly.Streams
21 (
21 (
22 IsStream (..)
22 IsStream (..)
23 , Streaming -- deprecated
23 , Streaming -- deprecated
24+ , MonadParallel
24− , MonadAsync
25+ , S.MonadAsync -- deprecated
25
26
26 -- * SVars
27 -- * SVars
27 , SVarSched (..)
28 , SVarSched (..)
@@ -48,9 +49,9 @@ module Streamly.Streams
48 , async
49 , async
49
50
50 -- * Merging Streams
51 -- * Merging Streams
51− , append
52+ , serial
52− , interleave
53+ , coserial
53− , aparallel
54+ , coparallel
54 , parallel
55 , parallel
55 , (<=>) --deprecated
56 , (<=>) --deprecated
56 , (<|) --deprecated
57 , (<|) --deprecated
@@ -58,22 +59,27 @@ module Streamly.Streams
58 -- * Stream Styles
59 -- * Stream Styles
59 , SerialT
60 , SerialT
60 , StreamT -- deprecated
61 , StreamT -- deprecated
62+ , CoserialT
61− , InterleavedT
63+ , InterleavedT -- deprecated
62− , AParallelT
64+ , CoparallelT
63 , AsyncT -- deprecated
65 , AsyncT -- deprecated
64 , ParallelT
66 , ParallelT
65 , ZipSerial
67 , ZipSerial
66 , ZipStream -- deprecated
68 , ZipStream -- deprecated
69+ , ZipParallel
67− , ZipAsync
70+ , ZipAsync -- deprecated
68
71
69 -- * Type Adapters
72 -- * Type Adapters
70 , serially
73 , serially
74+ , coserially
71− , interleaving
75+ , interleaving -- deprecated
72− , aparallely
76+ , coparallely
73 , asyncly -- deprecated
77 , asyncly -- deprecated
74 , parallely
78 , parallely
79+ , zipSerially
75− , zipping
80+ , zipping -- deprecated
81+ , zipParallely
76− , zippingAsync
82+ , zippingAsync -- deprecated
77 , adapt
83 , adapt
78
84
79 -- * Running Streams
85 -- * Running Streams
@@ -86,10 +92,10 @@ module Streamly.Streams
86
92
87 -- * Zipping
93 -- * Zipping
88 , zipWith
94 , zipWith
95+ , zipParallelWith
89− , zipAsyncWith
96+ , zipAsyncWith -- deprecated
90
97
91 -- * Fold Utilities
98 -- * Fold Utilities
92− -- $foldutils
93 , foldWith
99 , foldWith
94 , foldMapWith
100 , foldMapWith
95 , forEachWith
101 , forEachWith
@@ -107,7 +113,7 @@ import Control.Monad.State.Class (MonadState(..))
107import Control.Monad.Trans.Class (MonadTrans)
113import Control.Monad.Trans.Class (MonadTrans)
108import Data.Semigroup (Semigroup(..))
114import Data.Semigroup (Semigroup(..))
109import Prelude hiding (zipWith)
115import Prelude hiding (zipWith)
110−import Streamly.Core ( MonadAsync, Stream(Stream)
116+import Streamly.Core ( MonadParallel, Stream(Stream)
111 , SVar, SVarStyle(..)
117 , SVar, SVarStyle(..)
112 , SVarTag(..), SVarSched(..))
118 , SVarTag(..), SVarSched(..))
113import qualified Streamly.Core as S
119import qualified Streamly.Core as S
@@ -199,7 +205,7 @@ fromCallback :: IsStream t => (forall r. (a -> m r) -> m r) -> t m a
199fromCallback k = fromStream $ Stream $ \_ _ yld -> k (\a -> yld a Nothing)
205fromCallback k = fromStream $ Stream $ \_ _ yld -> k (\a -> yld a Nothing)
200
206
201-- | Read an SVar to get a stream.
207-- | Read an SVar to get a stream.
202−fromSVar :: (MonadAsync m, IsStream t) => SVar m a -> t m a
208+fromSVar :: (MonadParallel m, IsStream t) => SVar m a -> t m a
203fromSVar sv = fromStream $ S.fromStreamVar sv
209fromSVar sv = fromStream $ S.fromStreamVar sv
204
210
205------------------------------------------------------------------------------
211------------------------------------------------------------------------------
@@ -216,7 +222,9 @@ streamFold sv step blank m =
216 yield a (Just x) = step a (Just (fromStream x))
222 yield a (Just x) = step a (Just (fromStream x))
217 in (S.runStream (toStream m)) sv blank yield
223 in (S.runStream (toStream m)) sv blank yield
218
224
219−-- | Run a streaming composition, discard the results.
225+-- | Run a streaming composition, discard the results. By default it interprets
226+-- the stream as 'SerialT', to run other types of streams use the type adapting
227+-- combinators for example @runStream . 'parallely'@.
220runStream :: Monad m => SerialT m a -> m ()
228runStream :: Monad m => SerialT m a -> m ()
221runStream m = go (toStream m)
229runStream m = go (toStream m)
222 where
230 where
@@ -233,7 +241,7 @@ runStreaming = runStream . adapt
233
241
234-- | Write a stream to an 'SVar' in a non-blocking manner. The stream can then
242-- | Write a stream to an 'SVar' in a non-blocking manner. The stream can then
235-- be read back from the SVar using 'fromSVar'.
243-- be read back from the SVar using 'fromSVar'.
236−toSVar :: (IsStream t, MonadAsync m) => SVar m a -> t m a -> m ()
244+toSVar :: (IsStream t, MonadParallel m) => SVar m a -> t m a -> m ()
237toSVar sv m = S.toStreamVar sv (toStream m)
245toSVar sv m = S.toStreamVar sv (toStream m)
238
246
239------------------------------------------------------------------------------
247------------------------------------------------------------------------------
@@ -247,7 +255,7 @@ toSVar sv m = S.toStreamVar sv (toStream m)
247-- not drained fully we may have a thread blocked forever and once exhausted it
255-- not drained fully we may have a thread blocked forever and once exhausted it
248-- will always return 'empty'.
256-- will always return 'empty'.
249
257
250−async :: (IsStream t, MonadAsync m) => t m a -> m (t m a)
258+async :: (IsStream t, MonadParallel m) => t m a -> m (t m a)
251async m = do
259async m = do
252 sv <- S.newStreamVar1 (SVarStyle Disjunction LIFO) (toStream m)
260 sv <- S.newStreamVar1 (SVarStyle Disjunction LIFO) (toStream m)
253 return $ fromSVar sv
261 return $ fromSVar sv
@@ -309,8 +317,8 @@ async m = do
309newtype SerialT m a = SerialT {getSerialT :: Stream m a}
317newtype SerialT m a = SerialT {getSerialT :: Stream m a}
310 deriving (Semigroup, Monoid, MonadTrans, MonadIO, MonadThrow)
318 deriving (Semigroup, Monoid, MonadTrans, MonadIO, MonadThrow)
311
319
312−deriving instance MonadAsync m => Alternative (SerialT m)
320+deriving instance MonadParallel m => Alternative (SerialT m)
313−deriving instance MonadAsync m => MonadPlus (SerialT m)
321+deriving instance MonadParallel m => MonadPlus (SerialT m)
314deriving instance (MonadBase b m, Monad m) => MonadBase b (SerialT m)
322deriving instance (MonadBase b m, Monad m) => MonadBase b (SerialT m)
315deriving instance MonadError e m => MonadError e (SerialT m)
323deriving instance MonadError e m => MonadError e (SerialT m)
316deriving instance MonadReader r m => MonadReader r (SerialT m)
324deriving instance MonadReader r m => MonadReader r (SerialT m)
@@ -336,9 +344,9 @@ type StreamT = SerialT
336-- | Polymorphic version of the 'Semigroup' operation '<>' of 'SerialT'.
344-- | Polymorphic version of the 'Semigroup' operation '<>' of 'SerialT'.
337-- Appends two streams sequentially, yielding all elements from the first
345-- Appends two streams sequentially, yielding all elements from the first
338-- stream, and then all elements from the second stream.
346-- stream, and then all elements from the second stream.
339−{-# INLINE append #-}
347+{-# INLINE serial #-}
340−append :: IsStream t => t m a -> t m a -> t m a
348+serial :: IsStream t => t m a -> t m a -> t m a
341−append m1 m2 = fromStream $ S.append (toStream m1) (toStream m2)
349+serial m1 m2 = fromStream $ S.serial (toStream m1) (toStream m2)
342
350
343------------------------------------------------------------------------------
351------------------------------------------------------------------------------
344-- Monad
352-- Monad
@@ -416,10 +424,10 @@ instance (Monad m, Floating a) => Floating (SerialT m a) where
416 logBase = liftA2 logBase
424 logBase = liftA2 logBase
417
425
418------------------------------------------------------------------------------
426------------------------------------------------------------------------------
419−-- InterleavedT
427+-- CoserialT
420------------------------------------------------------------------------------
428------------------------------------------------------------------------------
421
429
422−-- | The 'Semigroup' instance of 'InterleavedT' interleaves two streams,
430+-- | The 'Semigroup' instance of 'CoserialT' interleaves two streams,
423-- yielding one element from each stream alternately.
431-- yielding one element from each stream alternately.
424--
432--
425-- @
433-- @
@@ -449,48 +457,51 @@ instance (Monad m, Floating a) => Floating (SerialT m a) where
449-- Note that interleaving composition can only combine a finite number of
457-- Note that interleaving composition can only combine a finite number of
450-- streams as it needs to retain state for each unfinished stream.
458-- streams as it needs to retain state for each unfinished stream.
451--
459--
452−newtype InterleavedT m a = InterleavedT {getInterleavedT :: Stream m a}
460+newtype CoserialT m a = CoserialT {getCoserialT :: Stream m a}
453 deriving (Monoid, MonadTrans, MonadIO, MonadThrow)
461 deriving (Monoid, MonadTrans, MonadIO, MonadThrow)
454
462
455−deriving instance MonadAsync m => Alternative (InterleavedT m)
463+deriving instance MonadParallel m => Alternative (CoserialT m)
456−deriving instance MonadAsync m => MonadPlus (InterleavedT m)
464+deriving instance MonadParallel m => MonadPlus (CoserialT m)
457−deriving instance (MonadBase b m, Monad m) => MonadBase b (InterleavedT m)
465+deriving instance (MonadBase b m, Monad m) => MonadBase b (CoserialT m)
458−deriving instance MonadError e m => MonadError e (InterleavedT m)
466+deriving instance MonadError e m => MonadError e (CoserialT m)
459−deriving instance MonadReader r m => MonadReader r (InterleavedT m)
467+deriving instance MonadReader r m => MonadReader r (CoserialT m)
460−deriving instance MonadState s m => MonadState s (InterleavedT m)
468+deriving instance MonadState s m => MonadState s (CoserialT m)
461
469
470+{-# DEPRECATED InterleavedT "Please use 'CoserialT' instead." #-}
471+type InterleavedT = CoserialT
472+
462−instance IsStream InterleavedT where
473+instance IsStream CoserialT where
463− toStream = getInterleavedT
474+ toStream = getCoserialT
464− fromStream = InterleavedT
475+ fromStream = CoserialT
465
476
466------------------------------------------------------------------------------
477------------------------------------------------------------------------------
467-- Semigroup
478-- Semigroup
468------------------------------------------------------------------------------
479------------------------------------------------------------------------------
469
480
470−-- | Polymorphic version of the 'Semigroup' operation '<>' of 'InterleavedT'.
481+-- | Polymorphic version of the 'Semigroup' operation '<>' of 'CoserialT'.
471-- Interleaves two streams, yielding one element from each stream alternately.
482-- Interleaves two streams, yielding one element from each stream alternately.
472−{-# INLINE interleave #-}
483+{-# INLINE coserial #-}
473−interleave :: IsStream t => t m a -> t m a -> t m a
484+coserial :: IsStream t => t m a -> t m a -> t m a
474−interleave m1 m2 = fromStream $ S.interleave (toStream m1) (toStream m2)
485+coserial m1 m2 = fromStream $ S.coserial (toStream m1) (toStream m2)
475
486
476−instance Semigroup (InterleavedT m a) where
487+instance Semigroup (CoserialT m a) where
477− (<>) = interleave
488+ (<>) = coserial
478
489
479infixr 5 <=>
490infixr 5 <=>
480
491
481−-- | Same as 'interleave'.
492+-- | Same as 'coserial'.
482−{-# Deprecated (<=>) "Please use '<>' of InterleavedT or 'interleave' instead." #-}
493+{-# DEPRECATED (<=>) "Please use 'coserial' instead." #-}
483{-# INLINE (<=>) #-}
494{-# INLINE (<=>) #-}
484(<=>) :: IsStream t => t m a -> t m a -> t m a
495(<=>) :: IsStream t => t m a -> t m a -> t m a
485−(<=>) = interleave
496+(<=>) = coserial
486
497
487------------------------------------------------------------------------------
498------------------------------------------------------------------------------
488-- Monad
499-- Monad
489------------------------------------------------------------------------------
500------------------------------------------------------------------------------
490
501
491−instance Monad m => Monad (InterleavedT m) where
502+instance Monad m => Monad (CoserialT m) where
492 return = pure
503 return = pure
493− (InterleavedT (Stream m)) >>= f = InterleavedT $ Stream $ \_ stp yld ->
504+ (CoserialT (Stream m)) >>= f = CoserialT $ Stream $ \_ stp yld ->
494 let run x = (S.runStream x) Nothing stp yld
505 let run x = (S.runStream x) Nothing stp yld
495 yield a Nothing = run $ toStream (f a)
506 yield a Nothing = run $ toStream (f a)
496 yield a (Just r) = run $ toStream $ f a <> (fromStream r >>= f)
507 yield a (Just r) = run $ toStream $ f a <> (fromStream r >>= f)
@@ -500,26 +511,26 @@ instance Monad m => Monad (InterleavedT m) where
500-- Applicative
511-- Applicative
501------------------------------------------------------------------------------
512------------------------------------------------------------------------------
502
513
503−instance Monad m => Applicative (InterleavedT m) where
514+instance Monad m => Applicative (CoserialT m) where
504− pure a = InterleavedT $ S.cons a Nothing
515+ pure a = CoserialT $ S.cons a Nothing
505 (<*>) = ap
516 (<*>) = ap
506
517
507------------------------------------------------------------------------------
518------------------------------------------------------------------------------
508-- Functor
519-- Functor
509------------------------------------------------------------------------------
520------------------------------------------------------------------------------
510
521
511−instance Monad m => Functor (InterleavedT m) where
522+instance Monad m => Functor (CoserialT m) where
512− fmap f (InterleavedT (Stream m)) = InterleavedT $ Stream $ \_ stp yld ->
523+ fmap f (CoserialT (Stream m)) = CoserialT $ Stream $ \_ stp yld ->
513 let yield a Nothing = yld (f a) Nothing
524 let yield a Nothing = yld (f a) Nothing
514 yield a (Just r) =
525 yield a (Just r) =
515− yld (f a) (Just (getInterleavedT (fmap f (InterleavedT r))))
526+ yld (f a) (Just (getCoserialT (fmap f (CoserialT r))))
516 in m Nothing stp yield
527 in m Nothing stp yield
517
528
518------------------------------------------------------------------------------
529------------------------------------------------------------------------------
519-- Num
530-- Num
520------------------------------------------------------------------------------
531------------------------------------------------------------------------------
521
532
522−instance (Monad m, Num a) => Num (InterleavedT m a) where
533+instance (Monad m, Num a) => Num (CoserialT m a) where
523 fromInteger n = pure (fromInteger n)
534 fromInteger n = pure (fromInteger n)
524
535
525 negate = fmap negate
536 negate = fmap negate
@@ -530,14 +541,14 @@ instance (Monad m, Num a) => Num (InterleavedT m a) where
530 (*) = liftA2 (*)
541 (*) = liftA2 (*)
531 (-) = liftA2 (-)
542 (-) = liftA2 (-)
532
543
533−instance (Monad m, Fractional a) => Fractional (InterleavedT m a) where
544+instance (Monad m, Fractional a) => Fractional (CoserialT m a) where
534 fromRational n = pure (fromRational n)
545 fromRational n = pure (fromRational n)
535
546
536 recip = fmap recip
547 recip = fmap recip
537
548
538 (/) = liftA2 (/)
549 (/) = liftA2 (/)
539
550
540−instance (Monad m, Floating a) => Floating (InterleavedT m a) where
551+instance (Monad m, Floating a) => Floating (CoserialT m a) where
541 pi = pure pi
552 pi = pure pi
542
553
543 exp = fmap exp
554 exp = fmap exp
@@ -560,7 +571,7 @@ instance (Monad m, Floating a) => Floating (InterleavedT m a) where
560 logBase = liftA2 logBase
571 logBase = liftA2 logBase
561
572
562------------------------------------------------------------------------------
573------------------------------------------------------------------------------
563−-- AParallelT
574+-- CoparallelT
564------------------------------------------------------------------------------
575------------------------------------------------------------------------------
565
576
566-- | Adaptive parallel, in a left to right 'Semigroup' composition it tries to
577-- | Adaptive parallel, in a left to right 'Semigroup' composition it tries to
@@ -570,7 +581,7 @@ instance (Monad m, Floating a) => Floating (InterleavedT m a) where
570-- enough for the consumer.
581-- enough for the consumer.
571--
582--
572-- @
583-- @
573−-- main = ('toList' . 'aparallely' $ (fromFoldable [1,2]) \<> (fromFoldable [3,4])) >>= print
584+-- main = ('toList' . 'coparallely' $ (fromFoldable [1,2]) \<> (fromFoldable [3,4])) >>= print
574-- @
585-- @
575-- @
586-- @
576-- [1,2,3,4]
587-- [1,2,3,4]
@@ -585,7 +596,7 @@ instance (Monad m, Floating a) => Floating (InterleavedT m a) where
585-- import "Streamly"
596-- import "Streamly"
586-- import Control.Concurrent
597-- import Control.Concurrent
587--
598--
588−-- main = 'runStream' . 'aparallely' $ do
599+-- main = 'runStream' . 'coparallely' $ do
589-- n <- return 3 \<\> return 2 \<\> return 1
600-- n <- return 3 \<\> return 2 \<\> return 1
590-- liftIO $ do
601-- liftIO $ do
591-- threadDelay (n * 1000000)
602-- threadDelay (n * 1000000)
@@ -602,45 +613,45 @@ instance (Monad m, Floating a) => Floating (InterleavedT m a) where
602-- Note that this composition can be used to combine infinite number of streams
613-- Note that this composition can be used to combine infinite number of streams
603-- as it explores only a bounded number of streams at a time.
614-- as it explores only a bounded number of streams at a time.
604--
615--
605−newtype AParallelT m a = AParallelT {getAParallelT :: Stream m a}
616+newtype CoparallelT m a = CoparallelT {getCoparallelT :: Stream m a}
606 deriving (MonadTrans)
617 deriving (MonadTrans)
607
618
608−deriving instance MonadAsync m => Monoid (AParallelT m a)
619+deriving instance MonadParallel m => Monoid (CoparallelT m a)
609−deriving instance MonadAsync m => Alternative (AParallelT m)
620+deriving instance MonadParallel m => Alternative (CoparallelT m)
610−deriving instance MonadAsync m => MonadPlus (AParallelT m)
621+deriving instance MonadParallel m => MonadPlus (CoparallelT m)
611−deriving instance MonadAsync m => MonadIO (AParallelT m)
622+deriving instance MonadParallel m => MonadIO (CoparallelT m)
612−deriving instance MonadAsync m => MonadThrow (AParallelT m)
623+deriving instance MonadParallel m => MonadThrow (CoparallelT m)
613−deriving instance (MonadBase b m, MonadAsync m) => MonadBase b (AParallelT m)
624+deriving instance (MonadBase b m, MonadParallel m) => MonadBase b (CoparallelT m)
614−deriving instance (MonadError e m, MonadAsync m) => MonadError e (AParallelT m)
625+deriving instance (MonadError e m, MonadParallel m) => MonadError e (CoparallelT m)
615−deriving instance (MonadReader r m, MonadAsync m) => MonadReader r (AParallelT m)
626+deriving instance (MonadReader r m, MonadParallel m) => MonadReader r (CoparallelT m)
616−deriving instance (MonadState s m, MonadAsync m) => MonadState s (AParallelT m)
627+deriving instance (MonadState s m, MonadParallel m) => MonadState s (CoparallelT m)
617
628
618−{-# DEPRECATED AsyncT "Please use 'AParallelT' instead." #-}
629+{-# DEPRECATED AsyncT "Please use 'CoparallelT' instead." #-}
619−type AsyncT = AParallelT
630+type AsyncT = CoparallelT
620
631
621−instance IsStream AParallelT where
632+instance IsStream CoparallelT where
622− toStream = getAParallelT
633+ toStream = getCoparallelT
623− fromStream = AParallelT
634+ fromStream = CoparallelT
624
635
625------------------------------------------------------------------------------
636------------------------------------------------------------------------------
626-- Semigroup
637-- Semigroup
627------------------------------------------------------------------------------
638------------------------------------------------------------------------------
628
639
629−-- | Polymorphic version of the 'Semigroup' operation '<>' of 'AParallelT', but
640+-- | Polymorphic version of the 'Semigroup' operation '<>' of 'CoparallelT', but
630-- polymorphic. Merges two streams possibly concurrently, preferring the
641-- polymorphic. Merges two streams possibly concurrently, preferring the
631-- elements from the left one when available.
642-- elements from the left one when available.
632−{-# INLINE aparallel #-}
643+{-# INLINE coparallel #-}
633−aparallel :: (IsStream t, MonadAsync m) => t m a -> t m a -> t m a
644+coparallel :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
634−aparallel m1 m2 = fromStream $ S.aparallel (toStream m1) (toStream m2)
645+coparallel m1 m2 = fromStream $ S.coparallel (toStream m1) (toStream m2)
635
646
636−instance MonadAsync m => Semigroup (AParallelT m a) where
647+instance MonadParallel m => Semigroup (CoparallelT m a) where
637− (<>) = aparallel
648+ (<>) = coparallel
638
649
639−-- | Same as 'aparallel'.
650+-- | Same as 'coparallel'.
640−{-# DEPRECATED (<|) "Please use 'aparallel' instead." #-}
651+{-# DEPRECATED (<|) "Please use 'coparallel' instead." #-}
641{-# INLINE (<|) #-}
652{-# INLINE (<|) #-}
642−(<|) :: (IsStream t, MonadAsync m) => t m a -> t m a -> t m a
653+(<|) :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
643−(<|) = aparallel
654+(<|) = coparallel
644
655
645------------------------------------------------------------------------------
656------------------------------------------------------------------------------
646-- Monad
657-- Monad
@@ -661,35 +672,35 @@ parbind par m f = go m
661 yield a (Just r) = run $ f a `par` go r
672 yield a (Just r) = run $ f a `par` go r
662 in g Nothing stp yield
673 in g Nothing stp yield
663
674
664−instance MonadAsync m => Monad (AParallelT m) where
675+instance MonadParallel m => Monad (CoparallelT m) where
665 return = pure
676 return = pure
666− (AParallelT m) >>= f = AParallelT $ parbind par m g
677+ (CoparallelT m) >>= f = CoparallelT $ parbind par m g
667− where g x = getAParallelT (f x)
678+ where g x = getCoparallelT (f x)
668 par = S.joinStreamVar2 (SVarStyle Conjunction LIFO)
679 par = S.joinStreamVar2 (SVarStyle Conjunction LIFO)
669
680
670------------------------------------------------------------------------------
681------------------------------------------------------------------------------
671-- Applicative
682-- Applicative
672------------------------------------------------------------------------------
683------------------------------------------------------------------------------
673
684
674−instance MonadAsync m => Applicative (AParallelT m) where
685+instance MonadParallel m => Applicative (CoparallelT m) where
675− pure a = AParallelT $ S.cons a Nothing
686+ pure a = CoparallelT $ S.cons a Nothing
676 (<*>) = ap
687 (<*>) = ap
677
688
678------------------------------------------------------------------------------
689------------------------------------------------------------------------------
679-- Functor
690-- Functor
680------------------------------------------------------------------------------
691------------------------------------------------------------------------------
681
692
682−instance Monad m => Functor (AParallelT m) where
693+instance Monad m => Functor (CoparallelT m) where
683− fmap f (AParallelT (Stream m)) = AParallelT $ Stream $ \_ stp yld ->
694+ fmap f (CoparallelT (Stream m)) = CoparallelT $ Stream $ \_ stp yld ->
684 let yield a Nothing = yld (f a) Nothing
695 let yield a Nothing = yld (f a) Nothing
685− yield a (Just r) = yld (f a) (Just (getAParallelT (fmap f (AParallelT r))))
696+ yield a (Just r) = yld (f a) (Just (getCoparallelT (fmap f (CoparallelT r))))
686 in m Nothing stp yield
697 in m Nothing stp yield
687
698
688------------------------------------------------------------------------------
699------------------------------------------------------------------------------
689-- Num
700-- Num
690------------------------------------------------------------------------------
701------------------------------------------------------------------------------
691
702
692−instance (MonadAsync m, Num a) => Num (AParallelT m a) where
703+instance (MonadParallel m, Num a) => Num (CoparallelT m a) where
693 fromInteger n = pure (fromInteger n)
704 fromInteger n = pure (fromInteger n)
694
705
695 negate = fmap negate
706 negate = fmap negate
@@ -700,14 +711,14 @@ instance (MonadAsync m, Num a) => Num (AParallelT m a) where
700 (*) = liftA2 (*)
711 (*) = liftA2 (*)
701 (-) = liftA2 (-)
712 (-) = liftA2 (-)
702
713
703−instance (MonadAsync m, Fractional a) => Fractional (AParallelT m a) where
714+instance (MonadParallel m, Fractional a) => Fractional (CoparallelT m a) where
704 fromRational n = pure (fromRational n)
715 fromRational n = pure (fromRational n)
705
716
706 recip = fmap recip
717 recip = fmap recip
707
718
708 (/) = liftA2 (/)
719 (/) = liftA2 (/)
709
720
710−instance (MonadAsync m, Floating a) => Floating (AParallelT m a) where
721+instance (MonadParallel m, Floating a) => Floating (CoparallelT m a) where
711 pi = pure pi
722 pi = pure pi
712
723
713 exp = fmap exp
724 exp = fmap exp
@@ -764,7 +775,7 @@ instance (MonadAsync m, Floating a) => Floating (AParallelT m a) where
764-- ThreadId 38: Delay 3
775-- ThreadId 38: Delay 3
765-- @
776-- @
766--
777--
767−-- Unlike 'AParallelT' all iterations are guaranteed to run fairly
778+-- Unlike 'CoparallelT' all iterations are guaranteed to run fairly
768-- concurrently, unconditionally.
779-- concurrently, unconditionally.
769--
780--
770-- Note that round robin composition can only combine a finite number of
781-- Note that round robin composition can only combine a finite number of
@@ -773,15 +784,15 @@ instance (MonadAsync m, Floating a) => Floating (AParallelT m a) where
773newtype ParallelT m a = ParallelT {getParallelT :: Stream m a}
784newtype ParallelT m a = ParallelT {getParallelT :: Stream m a}
774 deriving (MonadTrans)
785 deriving (MonadTrans)
775
786
776−deriving instance MonadAsync m => Monoid (ParallelT m a)
787+deriving instance MonadParallel m => Monoid (ParallelT m a)
777−deriving instance MonadAsync m => Alternative (ParallelT m)
788+deriving instance MonadParallel m => Alternative (ParallelT m)
778−deriving instance MonadAsync m => MonadPlus (ParallelT m)
789+deriving instance MonadParallel m => MonadPlus (ParallelT m)
779−deriving instance MonadAsync m => MonadIO (ParallelT m)
790+deriving instance MonadParallel m => MonadIO (ParallelT m)
780−deriving instance MonadAsync m => MonadThrow (ParallelT m)
791+deriving instance MonadParallel m => MonadThrow (ParallelT m)
781−deriving instance (MonadBase b m, MonadAsync m) => MonadBase b (ParallelT m)
792+deriving instance (MonadBase b m, MonadParallel m) => MonadBase b (ParallelT m)
782−deriving instance (MonadError e m, MonadAsync m) => MonadError e (ParallelT m)
793+deriving instance (MonadError e m, MonadParallel m) => MonadError e (ParallelT m)
783−deriving instance (MonadReader r m, MonadAsync m) => MonadReader r (ParallelT m)
794+deriving instance (MonadReader r m, MonadParallel m) => MonadReader r (ParallelT m)
784−deriving instance (MonadState s m, MonadAsync m) => MonadState s (ParallelT m)
795+deriving instance (MonadState s m, MonadParallel m) => MonadState s (ParallelT m)
785
796
786instance IsStream ParallelT where
797instance IsStream ParallelT where
787 toStream = getParallelT
798 toStream = getParallelT
@@ -794,17 +805,17 @@ instance IsStream ParallelT where
794-- | Polymorphic version of the 'Semigroup' operation '<>' of 'ParallelT'.
805-- | Polymorphic version of the 'Semigroup' operation '<>' of 'ParallelT'.
795-- Merges two streams concurrently choosing elements from both fairly.
806-- Merges two streams concurrently choosing elements from both fairly.
796{-# INLINE parallel #-}
807{-# INLINE parallel #-}
797−parallel :: (IsStream t, MonadAsync m) => t m a -> t m a -> t m a
808+parallel :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
798parallel m1 m2 = fromStream $ S.parallel (toStream m1) (toStream m2)
809parallel m1 m2 = fromStream $ S.parallel (toStream m1) (toStream m2)
799
810
800−instance MonadAsync m => Semigroup (ParallelT m a) where
811+instance MonadParallel m => Semigroup (ParallelT m a) where
801 (<>) = parallel
812 (<>) = parallel
802
813
803------------------------------------------------------------------------------
814------------------------------------------------------------------------------
804-- Monad
815-- Monad
805------------------------------------------------------------------------------
816------------------------------------------------------------------------------
806
817
807−instance MonadAsync m => Monad (ParallelT m) where
818+instance MonadParallel m => Monad (ParallelT m) where
808 return = pure
819 return = pure
809 (ParallelT m) >>= f = ParallelT $ parbind par m g
820 (ParallelT m) >>= f = ParallelT $ parbind par m g
810 where g x = getParallelT (f x)
821 where g x = getParallelT (f x)
@@ -814,7 +825,7 @@ instance MonadAsync m => Monad (ParallelT m) where
814-- Applicative
825-- Applicative
815------------------------------------------------------------------------------
826------------------------------------------------------------------------------
816
827
817−instance MonadAsync m => Applicative (ParallelT m) where
828+instance MonadParallel m => Applicative (ParallelT m) where
818 pure a = ParallelT $ S.cons a Nothing
829 pure a = ParallelT $ S.cons a Nothing
819 (<*>) = ap
830 (<*>) = ap
820
831
@@ -833,7 +844,7 @@ instance Monad m => Functor (ParallelT m) where
833-- Num
844-- Num
834------------------------------------------------------------------------------
845------------------------------------------------------------------------------
835
846
836−instance (MonadAsync m, Num a) => Num (ParallelT m a) where
847+instance (MonadParallel m, Num a) => Num (ParallelT m a) where
837 fromInteger n = pure (fromInteger n)
848 fromInteger n = pure (fromInteger n)
838
849
839 negate = fmap negate
850 negate = fmap negate
@@ -844,14 +855,14 @@ instance (MonadAsync m, Num a) => Num (ParallelT m a) where
844 (*) = liftA2 (*)
855 (*) = liftA2 (*)
845 (-) = liftA2 (-)
856 (-) = liftA2 (-)
846
857
847−instance (MonadAsync m, Fractional a) => Fractional (ParallelT m a) where
858+instance (MonadParallel m, Fractional a) => Fractional (ParallelT m a) where
848 fromRational n = pure (fromRational n)
859 fromRational n = pure (fromRational n)
849
860
850 recip = fmap recip
861 recip = fmap recip
851
862
852 (/) = liftA2 (/)
863 (/) = liftA2 (/)
853
864
854−instance (MonadAsync m, Floating a) => Floating (ParallelT m a) where
865+instance (MonadParallel m, Floating a) => Floating (ParallelT m a) where
855 pi = pure pi
866 pi = pure pi
856
867
857 exp = fmap exp
868 exp = fmap exp
@@ -892,11 +903,10 @@ zipWith f m1 m2 = fromStream $ go (toStream m1) (toStream m2)
892
903
893-- | The applicative instance of 'ZipSerial' zips a number of streams serially
904-- | The applicative instance of 'ZipSerial' zips a number of streams serially
894-- i.e. it produces one element from each stream serially and then zips all
905-- i.e. it produces one element from each stream serially and then zips all
895−-- those elements. Note, for convenience we have used the 'zipping' combinator
906+-- those elements.
896−-- in the following example instead of using a 'ZipSerial' type annotation.
897--
907--
898-- @
908-- @
899−-- main = (toList . 'zipping' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
909+-- main = (toList . 'zipSerially' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
900-- where s1 = fromFoldable [1, 2]
910-- where s1 = fromFoldable [1, 2]
901-- s2 = fromFoldable [3, 4]
911-- s2 = fromFoldable [3, 4]
902-- s3 = fromFoldable [5, 6]
912-- s3 = fromFoldable [5, 6]
@@ -915,7 +925,7 @@ newtype ZipSerial m a = ZipSerial {getZipSerial :: Stream m a}
915-- | Same as ZipSerial.
925-- | Same as ZipSerial.
916type ZipStream = ZipSerial
926type ZipStream = ZipSerial
917
927
918−deriving instance MonadAsync m => Alternative (ZipSerial m)
928+deriving instance MonadParallel m => Alternative (ZipSerial m)
919
929
920instance Monad m => Functor (ZipSerial m) where
930instance Monad m => Functor (ZipSerial m) where
921 fmap f (ZipSerial (Stream m)) = ZipSerial $ Stream $ \_ stp yld ->
931 fmap f (ZipSerial (Stream m)) = ZipSerial $ Stream $ \_ stp yld ->
@@ -976,20 +986,25 @@ instance (Monad m, Floating a) => Floating (ZipSerial m a) where
976-- Parallely Zipping Streams
986-- Parallely Zipping Streams
977------------------------------------------------------------------------------
987------------------------------------------------------------------------------
978
988
979−-- | Zip two streams asyncly (i.e. both the elements being zipped are generated
989+-- | Zip two streams concurrently (i.e. both the elements being zipped are
980−-- concurrently) using a pure zipping function.
990+-- generated concurrently) using a pure zipping function.
981−zipAsyncWith :: (IsStream t, MonadAsync m)
991+zipParallelWith :: (IsStream t, MonadParallel m)
982 => (a -> b -> c) -> t m a -> t m b -> t m c
992 => (a -> b -> c) -> t m a -> t m b -> t m c
983−zipAsyncWith f m1 m2 = fromStream $ Stream $ \_ stp yld -> do
993+zipParallelWith f m1 m2 = fromStream $ Stream $ \_ stp yld -> do
984 ma <- async m1
994 ma <- async m1
985 mb <- async m2
995 mb <- async m2
986 (S.runStream (toStream (zipWith f ma mb))) Nothing stp yld
996 (S.runStream (toStream (zipWith f ma mb))) Nothing stp yld
987
997
998+{-# DEPRECATED zipAsyncWith "Please use zipParallelWith instead." #-}
999+zipAsyncWith :: (IsStream t, MonadParallel m)
1000+ => (a -> b -> c) -> t m a -> t m b -> t m c
1001+zipAsyncWith = zipParallelWith
1002+
988-- | Like 'ZipSerial' but zips in parallel, it generates all the elements to
1003-- | Like 'ZipSerial' but zips in parallel, it generates all the elements to
989-- be zipped concurrently.
1004-- be zipped concurrently.
990--
1005--
991-- @
1006-- @
992−-- main = (toList . 'zippingAsync' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
1007+-- main = (toList . 'zipParallely' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
993-- where s1 = fromFoldable [1, 2]
1008-- where s1 = fromFoldable [1, 2]
994-- s2 = fromFoldable [3, 4]
1009-- s2 = fromFoldable [3, 4]
995-- s3 = fromFoldable [5, 6]
1010-- s3 = fromFoldable [5, 6]
@@ -1001,27 +1016,30 @@ zipAsyncWith f m1 m2 = fromStream $ Stream $ \_ stp yld -> do
1001-- The 'Semigroup' instance of this type works the same way as that of
1016-- The 'Semigroup' instance of this type works the same way as that of
1002-- 'SerialT'.
1017-- 'SerialT'.
1003--
1018--
1004−newtype ZipAsync m a = ZipAsync {getZipAsync :: Stream m a}
1019+newtype ZipParallel m a = ZipParallel {getZipParallel :: Stream m a}
1005 deriving (Semigroup, Monoid)
1020 deriving (Semigroup, Monoid)
1006
1021
1022+{-# DEPRECATED ZipAsync "Please use ZipParallel instead." #-}
1023+type ZipAsync = ZipParallel
1024+
1007−deriving instance MonadAsync m => Alternative (ZipAsync m)
1025+deriving instance MonadParallel m => Alternative (ZipParallel m)
1008
1026
1009−instance Monad m => Functor (ZipAsync m) where
1027+instance Monad m => Functor (ZipParallel m) where
1010− fmap f (ZipAsync (Stream m)) = ZipAsync $ Stream $ \_ stp yld ->
1028+ fmap f (ZipParallel (Stream m)) = ZipParallel $ Stream $ \_ stp yld ->
1011 let yield a Nothing = yld (f a) Nothing
1029 let yield a Nothing = yld (f a) Nothing
1012 yield a (Just r) = yld (f a)
1030 yield a (Just r) = yld (f a)
1013− (Just (getZipAsync (fmap f (ZipAsync r))))
1031+ (Just (getZipParallel (fmap f (ZipParallel r))))
1014 in m Nothing stp yield
1032 in m Nothing stp yield
1015
1033
1016−instance MonadAsync m => Applicative (ZipAsync m) where
1034+instance MonadParallel m => Applicative (ZipParallel m) where
1017− pure = ZipAsync . S.repeat
1035+ pure = ZipParallel . S.repeat
1018− (<*>) = zipAsyncWith id
1036+ (<*>) = zipParallelWith id
1019
1037
1020−instance IsStream ZipAsync where
1038+instance IsStream ZipParallel where
1021− toStream = getZipAsync
1039+ toStream = getZipParallel
1022− fromStream = ZipAsync
1040+ fromStream = ZipParallel
1023
1041
1024−instance (MonadAsync m, Num a) => Num (ZipAsync m a) where
1042+instance (MonadParallel m, Num a) => Num (ZipParallel m a) where
1025 fromInteger n = pure (fromInteger n)
1043 fromInteger n = pure (fromInteger n)
1026
1044
1027 negate = fmap negate
1045 negate = fmap negate
@@ -1032,14 +1050,14 @@ instance (MonadAsync m, Num a) => Num (ZipAsync m a) where
1032 (*) = liftA2 (*)
1050 (*) = liftA2 (*)
1033 (-) = liftA2 (-)
1051 (-) = liftA2 (-)
1034
1052
1035−instance (MonadAsync m, Fractional a) => Fractional (ZipAsync m a) where
1053+instance (MonadParallel m, Fractional a) => Fractional (ZipParallel m a) where
1036 fromRational n = pure (fromRational n)
1054 fromRational n = pure (fromRational n)
1037
1055
1038 recip = fmap recip
1056 recip = fmap recip
1039
1057
1040 (/) = liftA2 (/)
1058 (/) = liftA2 (/)
1041
1059
1042−instance (MonadAsync m, Floating a) => Floating (ZipAsync m a) where
1060+instance (MonadParallel m, Floating a) => Floating (ZipParallel m a) where
1043 pi = pure pi
1061 pi = pure pi
1044
1062
1045 exp = fmap exp
1063 exp = fmap exp
@@ -1073,30 +1091,45 @@ adapt = fromStream . toStream
1073serially :: IsStream t => SerialT m a -> t m a
1091serially :: IsStream t => SerialT m a -> t m a
1074serially = adapt
1092serially = adapt
1075
1093
1076−-- | Fix the type of a polymorphic stream as 'InterleavedT'.
1094+-- | Fix the type of a polymorphic stream as 'CoserialT'.
1077−interleaving :: IsStream t => InterleavedT m a -> t m a
1095+coserially :: IsStream t => CoserialT m a -> t m a
1078−interleaving = adapt
1096+coserially = adapt
1079
1097
1080−-- | Fix the type of a polymorphic stream as 'AParallelT'.
1098+-- | Same as 'coserially'.
1099+{-# DEPRECATED interleaving "Please use coserially instead." #-}
1081−aparallely :: IsStream t => AParallelT m a -> t m a
1100+interleaving :: IsStream t => CoserialT m a -> t m a
1082−aparallely = adapt
1101+interleaving = coserially
1083
1102
1084−-- | Same as 'aparallely'.
1103+-- | Fix the type of a polymorphic stream as 'CoparallelT'.
1104+coparallely :: IsStream t => CoparallelT m a -> t m a
1105+coparallely = adapt
1106+
1107+-- | Same as 'coparallely'.
1085−{-# DEPRECATED asyncly "Please use aparallely instead." #-}
1108+{-# DEPRECATED asyncly "Please use coparallely instead." #-}
1086−asyncly :: IsStream t => AParallelT m a -> t m a
1109+asyncly :: IsStream t => CoparallelT m a -> t m a
1087−asyncly = aparallely
1110+asyncly = coparallely
1088
1111
1089-- | Fix the type of a polymorphic stream as 'ParallelT'.
1112-- | Fix the type of a polymorphic stream as 'ParallelT'.
1090parallely :: IsStream t => ParallelT m a -> t m a
1113parallely :: IsStream t => ParallelT m a -> t m a
1091parallely = adapt
1114parallely = adapt
1092
1115
1093-- | Fix the type of a polymorphic stream as 'ZipSerial'.
1116-- | Fix the type of a polymorphic stream as 'ZipSerial'.
1117+zipSerially :: IsStream t => ZipSerial m a -> t m a
1118+zipSerially = adapt
1119+
1120+-- | Same as 'zipParallely'.
1121+{-# DEPRECATED zipping "Please use zipSerially instead." #-}
1094zipping :: IsStream t => ZipSerial m a -> t m a
1122zipping :: IsStream t => ZipSerial m a -> t m a
1095−zipping = adapt
1123+zipping = zipSerially
1096
1124
1097−-- | Fix the type of a polymorphic stream as 'ZipAsync'.
1125+-- | Fix the type of a polymorphic stream as 'ZipParallel'.
1098−zippingAsync :: IsStream t => ZipAsync m a -> t m a
1126+zipParallely :: IsStream t => ZipParallel m a -> t m a
1099−zippingAsync = adapt
1127+zipParallely = adapt
1128+
1129+-- | Same as 'zipParallely'.
1130+{-# DEPRECATED zippingAsync "Please use zipParallely instead." #-}
1131+zippingAsync :: IsStream t => ZipParallel m a -> t m a
1132+zippingAsync = zipParallely
1100
1133
1101-------------------------------------------------------------------------------
1134-------------------------------------------------------------------------------
1102-- Running Streams, convenience functions specialized to types
1135-- Running Streams, convenience functions specialized to types
@@ -1107,15 +1140,15 @@ zippingAsync = adapt
1107runStreamT :: Monad m => SerialT m a -> m ()
1140runStreamT :: Monad m => SerialT m a -> m ()
1108runStreamT = runStream
1141runStreamT = runStream
1109
1142
1110−-- | Same as @runStream . interleaving@.
1143+-- | Same as @runStream . coserially@.
1111{-# DEPRECATED runInterleavedT "Please use 'runStream . interleaving' instead." #-}
1144{-# DEPRECATED runInterleavedT "Please use 'runStream . interleaving' instead." #-}
1112runInterleavedT :: Monad m => InterleavedT m a -> m ()
1145runInterleavedT :: Monad m => InterleavedT m a -> m ()
1113−runInterleavedT = runStream . interleaving
1146+runInterleavedT = runStream . coserially
1114
1147
1115−-- | Same as @runStream . aparallely@.
1148+-- | Same as @runStream . coparallely@.
1116−{-# DEPRECATED runAsyncT "Please use 'runStream . aparallely' instead." #-}
1149+{-# DEPRECATED runAsyncT "Please use 'runStream . coparallely' instead." #-}
1117−runAsyncT :: Monad m => AParallelT m a -> m ()
1150+runAsyncT :: Monad m => CoparallelT m a -> m ()
1118−runAsyncT = runStream . aparallely
1151+runAsyncT = runStream . coparallely
1119
1152
1120-- | Same as @runStream . parallely@.
1153-- | Same as @runStream . parallely@.
1121{-# DEPRECATED runParallelT "Please use 'runStream . parallely' instead." #-}
1154{-# DEPRECATED runParallelT "Please use 'runStream . parallely' instead." #-}
@@ -1123,38 +1156,33 @@ runParallelT :: Monad m => ParallelT m a -> m ()
1123runParallelT = runStream . parallely
1156runParallelT = runStream . parallely
1124
1157
1125-- | Same as @runStream . zipping@.
1158-- | Same as @runStream . zipping@.
1126−{-# DEPRECATED runZipStream "Please use 'runStream . zipping instead." #-}
1159+{-# DEPRECATED runZipStream "Please use 'runStream . zipSerially instead." #-}
1127runZipStream :: Monad m => ZipSerial m a -> m ()
1160runZipStream :: Monad m => ZipSerial m a -> m ()
1128−runZipStream = runStream . zipping
1161+runZipStream = runStream . zipSerially
1129
1162
1130-- | Same as @runStream . zippingAsync@.
1163-- | Same as @runStream . zippingAsync@.
1131−{-# DEPRECATED runZipAsync "Please use 'runStream . zippingAsync instead." #-}
1164+{-# DEPRECATED runZipAsync "Please use 'runStream . zipParallely instead." #-}
1132−runZipAsync :: Monad m => ZipAsync m a -> m ()
1165+runZipAsync :: Monad m => ZipParallel m a -> m ()
1133−runZipAsync = runStream . zippingAsync
1166+runZipAsync = runStream . zipParallely
1134
1167
1135------------------------------------------------------------------------------
1168------------------------------------------------------------------------------
1136-- Fold Utilities
1169-- Fold Utilities
1137------------------------------------------------------------------------------
1170------------------------------------------------------------------------------
1138
1171
1139−-- $foldutils
1172+-- | A variant of 'Data.Foldable.fold' that allows you to fold a 'Foldable'
1140−-- These utilities are designed to pass the first argument as one of the sum
1173+-- container of streams using the specified stream sum operation.
1141−-- style composition operators (i.e. '<>', '<=>', '<|', '<|>') to conveniently
1142−-- fold a container using any style of stream composition.
1143−
1144−-- | Like the 'Prelude' 'fold' but allows you to specify a binary sum style
1145−-- stream composition operator to fold a container of streams.
1146--
1174--
1147−-- @foldWith (<>) $ map return [1..3]@
1175+-- @foldWith 'parallel' $ map return [1..3]@
1148{-# INLINABLE foldWith #-}
1176{-# INLINABLE foldWith #-}
1149foldWith :: (IsStream t, Foldable f)
1177foldWith :: (IsStream t, Foldable f)
1150 => (t m a -> t m a -> t m a) -> f (t m a) -> t m a
1178 => (t m a -> t m a -> t m a) -> f (t m a) -> t m a
1151foldWith f = foldr f nil
1179foldWith f = foldr f nil
1152
1180
1153−-- | Like 'foldMap' but allows you to specify a binary sum style composition
1181+-- | A variant of 'foldMap' that allows you to map a monadic streaming action
1154−-- operator to fold a container of streams. Maps a monadic streaming action on
1182+-- on a 'Foldable' container and then fold it using the specified stream sum
1155−-- the container before folding it.
1183+-- operation.
1156--
1184--
1157−-- @foldMapWith (<>) return [1..3]@
1185+-- @foldMapWith 'parallel' return [1..3]@
1158{-# INLINABLE foldMapWith #-}
1186{-# INLINABLE foldMapWith #-}
1159foldMapWith :: (IsStream t, Foldable f)
1187foldMapWith :: (IsStream t, Foldable f)
1160 => (t m b -> t m b -> t m b) -> (a -> t m b) -> f a -> t m b
1188 => (t m b -> t m b -> t m b) -> (a -> t m b) -> f a -> t m b
test/Main.hs+42−42
@@ -19,11 +19,11 @@ singleton a = a .: nil
19toListSerial :: SerialT IO a -> IO [a]
19toListSerial :: SerialT IO a -> IO [a]
20toListSerial = A.toList . serially
20toListSerial = A.toList . serially
21
21
22−toListInterleaved :: InterleavedT IO a -> IO [a]
22+toListInterleaved :: CoserialT IO a -> IO [a]
23−toListInterleaved = A.toList . interleaving
23+toListInterleaved = A.toList . coserially
24
24
25−toListAsync :: AParallelT IO a -> IO [a]
25+toListAsync :: CoparallelT IO a -> IO [a]
26−toListAsync = A.toList . aparallely
26+toListAsync = A.toList . coparallely
27
27
28toListParallel :: ParallelT IO a -> IO [a]
28toListParallel :: ParallelT IO a -> IO [a]
29toListParallel = A.toList . parallely
29toListParallel = A.toList . parallely
@@ -88,19 +88,19 @@ main = hspec $ do
88 ---------------------------------------------------------------------------
88 ---------------------------------------------------------------------------
89
89
90 describe "Serial Composition" $ compose serially mempty id
90 describe "Serial Composition" $ compose serially mempty id
91− describe "Interleaved Composition" $ compose interleaving mempty sort
91+ describe "Interleaved Composition" $ compose coserially mempty sort
92− describe "Left biased parallel Composition" $ compose aparallely mempty sort
92+ describe "Left biased parallel Composition" $ compose coparallely mempty sort
93 describe "Fair parallel Composition" $ compose parallely mempty sort
93 describe "Fair parallel Composition" $ compose parallely mempty sort
94− describe "Semigroup Composition for ZipSerial" $ compose zipping mempty id
94+ describe "Semigroup Composition for ZipSerial" $ compose zipSerially mempty id
95− describe "Semigroup Composition for ZipAsync" $ compose zippingAsync mempty id
95+ describe "Semigroup Composition for ZipAsync" $ compose zipParallely mempty id
96 -- XXX need to check alternative compositions as well
96 -- XXX need to check alternative compositions as well
97 ---------------------------------------------------------------------------
97 ---------------------------------------------------------------------------
98 -- Monoidal Composition ordering checks
98 -- Monoidal Composition ordering checks
99 ---------------------------------------------------------------------------
99 ---------------------------------------------------------------------------
100
100
101− describe "Serial interleaved ordering check" $ interleaveCheck interleaving
101+ describe "Serial interleaved ordering check" $ interleaveCheck coserially
102 describe "Parallel interleaved ordering check" $ interleaveCheck parallely
102 describe "Parallel interleaved ordering check" $ interleaveCheck parallely
103− describe "Left biased parallel time order check" $ parallelCheck aparallely
103+ describe "Left biased parallel time order check" $ parallelCheck coparallely
104 describe "Fair parallel time order check" $ parallelCheck parallely
104 describe "Fair parallel time order check" $ parallelCheck parallely
105
105
106 ---------------------------------------------------------------------------
106 ---------------------------------------------------------------------------
@@ -112,7 +112,7 @@ main = hspec $ do
112
112
113 describe "<> and <=>" $ composeAndComposeSimple
113 describe "<> and <=>" $ composeAndComposeSimple
114 serially
114 serially
115− interleaving
115+ coserially
116 ([ [1 .. 9]
116 ([ [1 .. 9]
117 , [1 .. 9]
117 , [1 .. 9]
118 , [1, 3, 2, 4, 6, 5, 7, 9, 8]
118 , [1, 3, 2, 4, 6, 5, 7, 9, 8]
@@ -120,8 +120,8 @@ main = hspec $ do
120 ])
120 ])
121
121
122 describe "<=> and <=>" $ composeAndComposeSimple
122 describe "<=> and <=>" $ composeAndComposeSimple
123− interleaving
123+ coserially
124− interleaving
124+ coserially
125 ([ [1, 4, 2, 7, 3, 5, 8, 6, 9]
125 ([ [1, 4, 2, 7, 3, 5, 8, 6, 9]
126 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
126 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
127 , [1, 4, 3, 7, 2, 6, 9, 5, 8]
127 , [1, 4, 3, 7, 2, 6, 9, 5, 8]
@@ -129,7 +129,7 @@ main = hspec $ do
129 ])
129 ])
130
130
131 describe "<=> and <>" $ composeAndComposeSimple
131 describe "<=> and <>" $ composeAndComposeSimple
132− interleaving
132+ coserially
133 serially
133 serially
134 ([ [1, 4, 2, 7, 3, 5, 8, 6, 9]
134 ([ [1, 4, 2, 7, 3, 5, 8, 6, 9]
135 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
135 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
@@ -183,7 +183,7 @@ main = hspec $ do
183 ---------------------------------------------------------------------------
183 ---------------------------------------------------------------------------
184
184
185 describe "Serial loops (<>)" $ loops serially id reverse
185 describe "Serial loops (<>)" $ loops serially id reverse
186− describe "Left biased parallel loops (<|)" $ loops aparallely sort sort
186+ describe "Left biased parallel loops (<|)" $ loops coparallely sort sort
187 describe "Fair parallel loops (<|>)" $ loops parallely sort sort
187 describe "Fair parallel loops (<|>)" $ loops parallely sort sort
188
188
189 ---------------------------------------------------------------------------
189 ---------------------------------------------------------------------------
@@ -191,23 +191,23 @@ main = hspec $ do
191 ---------------------------------------------------------------------------
191 ---------------------------------------------------------------------------
192
192
193 describe "Bind and compose1" $ bindAndComposeSimple serially serially
193 describe "Bind and compose1" $ bindAndComposeSimple serially serially
194− describe "Bind and compose2" $ bindAndComposeSimple serially interleaving
194+ describe "Bind and compose2" $ bindAndComposeSimple serially coserially
195− describe "Bind and compose3" $ bindAndComposeSimple serially aparallely
195+ describe "Bind and compose3" $ bindAndComposeSimple serially coparallely
196 describe "Bind and compose4" $ bindAndComposeSimple serially parallely
196 describe "Bind and compose4" $ bindAndComposeSimple serially parallely
197
197
198− describe "Bind and compose1" $ bindAndComposeSimple interleaving serially
198+ describe "Bind and compose1" $ bindAndComposeSimple coserially serially
199− describe "Bind and compose2" $ bindAndComposeSimple interleaving interleaving
199+ describe "Bind and compose2" $ bindAndComposeSimple coserially coserially
200− describe "Bind and compose3" $ bindAndComposeSimple interleaving aparallely
200+ describe "Bind and compose3" $ bindAndComposeSimple coserially coparallely
201− describe "Bind and compose4" $ bindAndComposeSimple interleaving parallely
201+ describe "Bind and compose4" $ bindAndComposeSimple coserially parallely
202
202
203− describe "Bind and compose1" $ bindAndComposeSimple aparallely serially
203+ describe "Bind and compose1" $ bindAndComposeSimple coparallely serially
204− describe "Bind and compose2" $ bindAndComposeSimple aparallely interleaving
204+ describe "Bind and compose2" $ bindAndComposeSimple coparallely coserially
205− describe "Bind and compose3" $ bindAndComposeSimple aparallely aparallely
205+ describe "Bind and compose3" $ bindAndComposeSimple coparallely coparallely
206− describe "Bind and compose4" $ bindAndComposeSimple aparallely parallely
206+ describe "Bind and compose4" $ bindAndComposeSimple coparallely parallely
207
207
208 describe "Bind and compose1" $ bindAndComposeSimple parallely serially
208 describe "Bind and compose1" $ bindAndComposeSimple parallely serially
209− describe "Bind and compose2" $ bindAndComposeSimple parallely interleaving
209+ describe "Bind and compose2" $ bindAndComposeSimple parallely coserially
210− describe "Bind and compose3" $ bindAndComposeSimple parallely aparallely
210+ describe "Bind and compose3" $ bindAndComposeSimple parallely coparallely
211 describe "Bind and compose4" $ bindAndComposeSimple parallely parallely
211 describe "Bind and compose4" $ bindAndComposeSimple parallely parallely
212
212
213 let fldr, fldl :: (IsStream t, Semigroup (t IO Int)) => [t IO Int] -> t IO Int
213 let fldr, fldl :: (IsStream t, Semigroup (t IO Int)) => [t IO Int] -> t IO Int
@@ -217,36 +217,36 @@ main = hspec $ do
217 forM_ [fldr, fldl] $ \k ->
217 forM_ [fldr, fldl] $ \k ->
218 describe "Bind and compose" $ bindAndComposeHierarchy serially serially k
218 describe "Bind and compose" $ bindAndComposeHierarchy serially serially k
219 forM_ [fldr, fldl] $ \k ->
219 forM_ [fldr, fldl] $ \k ->
220− describe "Bind and compose" $ bindAndComposeHierarchy serially interleaving k
220+ describe "Bind and compose" $ bindAndComposeHierarchy serially coserially k
221 forM_ [fldr, fldl] $ \k ->
221 forM_ [fldr, fldl] $ \k ->
222− describe "Bind and compose" $ bindAndComposeHierarchy serially aparallely k
222+ describe "Bind and compose" $ bindAndComposeHierarchy serially coparallely k
223 forM_ [fldr, fldl] $ \k ->
223 forM_ [fldr, fldl] $ \k ->
224 describe "Bind and compose" $ bindAndComposeHierarchy serially parallely k
224 describe "Bind and compose" $ bindAndComposeHierarchy serially parallely k
225
225
226 forM_ [fldr, fldl] $ \k ->
226 forM_ [fldr, fldl] $ \k ->
227− describe "Bind and compose" $ bindAndComposeHierarchy interleaving serially k
227+ describe "Bind and compose" $ bindAndComposeHierarchy coserially serially k
228 forM_ [fldr, fldl] $ \k ->
228 forM_ [fldr, fldl] $ \k ->
229− describe "Bind and compose" $ bindAndComposeHierarchy interleaving interleaving k
229+ describe "Bind and compose" $ bindAndComposeHierarchy coserially coserially k
230 forM_ [fldr, fldl] $ \k ->
230 forM_ [fldr, fldl] $ \k ->
231− describe "Bind and compose" $ bindAndComposeHierarchy interleaving aparallely k
231+ describe "Bind and compose" $ bindAndComposeHierarchy coserially coparallely k
232 forM_ [fldr, fldl] $ \k ->
232 forM_ [fldr, fldl] $ \k ->
233− describe "Bind and compose" $ bindAndComposeHierarchy interleaving parallely k
233+ describe "Bind and compose" $ bindAndComposeHierarchy coserially parallely k
234
234
235 forM_ [fldr, fldl] $ \k ->
235 forM_ [fldr, fldl] $ \k ->
236− describe "Bind and compose" $ bindAndComposeHierarchy aparallely serially k
236+ describe "Bind and compose" $ bindAndComposeHierarchy coparallely serially k
237 forM_ [fldr, fldl] $ \k ->
237 forM_ [fldr, fldl] $ \k ->
238− describe "Bind and compose" $ bindAndComposeHierarchy aparallely interleaving k
238+ describe "Bind and compose" $ bindAndComposeHierarchy coparallely coserially k
239 forM_ [fldr, fldl] $ \k ->
239 forM_ [fldr, fldl] $ \k ->
240− describe "Bind and compose" $ bindAndComposeHierarchy aparallely aparallely k
240+ describe "Bind and compose" $ bindAndComposeHierarchy coparallely coparallely k
241 forM_ [fldr, fldl] $ \k ->
241 forM_ [fldr, fldl] $ \k ->
242− describe "Bind and compose" $ bindAndComposeHierarchy aparallely parallely k
242+ describe "Bind and compose" $ bindAndComposeHierarchy coparallely parallely k
243
243
244 forM_ [fldr, fldl] $ \k ->
244 forM_ [fldr, fldl] $ \k ->
245 describe "Bind and compose" $ bindAndComposeHierarchy parallely serially k
245 describe "Bind and compose" $ bindAndComposeHierarchy parallely serially k
246 forM_ [fldr, fldl] $ \k ->
246 forM_ [fldr, fldl] $ \k ->
247− describe "Bind and compose" $ bindAndComposeHierarchy parallely interleaving k
247+ describe "Bind and compose" $ bindAndComposeHierarchy parallely coserially k
248 forM_ [fldr, fldl] $ \k ->
248 forM_ [fldr, fldl] $ \k ->
249− describe "Bind and compose" $ bindAndComposeHierarchy parallely aparallely k
249+ describe "Bind and compose" $ bindAndComposeHierarchy parallely coparallely k
250 forM_ [fldr, fldl] $ \k ->
250 forM_ [fldr, fldl] $ \k ->
251 describe "Bind and compose" $ bindAndComposeHierarchy parallely parallely k
251 describe "Bind and compose" $ bindAndComposeHierarchy parallely parallely k
252
252
@@ -553,11 +553,11 @@ mixedOps = do
553 x1 <- parallely $ return 1 <> return 2
553 x1 <- parallely $ return 1 <> return 2
554 liftIO $ return ()
554 liftIO $ return ()
555 liftIO $ putStr ""
555 liftIO $ putStr ""
556− y1 <- aparallely $ return 1 <> return 2
556+ y1 <- coparallely $ return 1 <> return 2
557 z1 <- do
557 z1 <- do
558 x11 <- return 1 <> return 2
558 x11 <- return 1 <> return 2
559− y11 <- aparallely $ return 1 <> return 2
559+ y11 <- coparallely $ return 1 <> return 2
560− z11 <- interleaving $ return 1 <> return 2
560+ z11 <- coserially $ return 1 <> return 2
561 liftIO $ return ()
561 liftIO $ return ()
562 liftIO $ putStr ""
562 liftIO $ putStr ""
563 return (x11 + y11 + z11)
563 return (x11 + y11 + z11)
test/Prop.hs+59−59
@@ -260,7 +260,7 @@ zipMonadic constr t eq (a, b) =
260 stream2 <-
260 stream2 <-
261 run
261 run
262 ((A.toList . t)
262 ((A.toList . t)
263− (A.zipAsyncWithM (\x y -> return (x, y)) (constr a) (constr b)))
263+ (A.zipParallelWithM (\x y -> return (x, y)) (constr a) (constr b)))
264 let list = getZipList $ (,) <$> ZipList a <*> ZipList b
264 let list = getZipList $ (,) <$> ZipList a <*> ZipList b
265 equals eq stream1 list
265 equals eq stream1 list
266 equals eq stream2 list
266 equals eq stream2 list
@@ -316,24 +316,24 @@ main = hspec $ do
316 describe "Functor operations" $ do
316 describe "Functor operations" $ do
317 functorOps A.fromFoldable "serially" serially (==)
317 functorOps A.fromFoldable "serially" serially (==)
318 functorOps folded "serially folded" serially (==)
318 functorOps folded "serially folded" serially (==)
319− functorOps A.fromFoldable "interleaving" interleaving (==)
319+ functorOps A.fromFoldable "coserially" coserially (==)
320− functorOps folded "interleaving folded" interleaving (==)
320+ functorOps folded "coserially folded" coserially (==)
321− functorOps A.fromFoldable "aparallely" aparallely sortEq
321+ functorOps A.fromFoldable "coparallely" coparallely sortEq
322− functorOps folded "aparallely folded" aparallely sortEq
322+ functorOps folded "coparallely folded" coparallely sortEq
323 functorOps A.fromFoldable "parallely" parallely sortEq
323 functorOps A.fromFoldable "parallely" parallely sortEq
324 functorOps folded "parallely folded" parallely sortEq
324 functorOps folded "parallely folded" parallely sortEq
325− functorOps A.fromFoldable "zipping" zipping (==)
325+ functorOps A.fromFoldable "zipSerially" zipSerially (==)
326− functorOps folded "zipping folded" zipping (==)
326+ functorOps folded "zipSerially folded" zipSerially (==)
327− functorOps A.fromFoldable "zippingAsync" zippingAsync (==)
327+ functorOps A.fromFoldable "zipParallely" zipParallely (==)
328− functorOps folded "zippingAsync folded" zippingAsync (==)
328+ functorOps folded "zipParallely folded" zipParallely (==)
329
329
330 describe "Semigroup operations" $ do
330 describe "Semigroup operations" $ do
331 semigroupOps "serially" serially (==)
331 semigroupOps "serially" serially (==)
332− semigroupOps "interleaving" interleaving (==)
332+ semigroupOps "coserially" coserially (==)
333− semigroupOps "aparallely" aparallely sortEq
333+ semigroupOps "coparallely" coparallely sortEq
334 semigroupOps "parallely" parallely sortEq
334 semigroupOps "parallely" parallely sortEq
335− semigroupOps "zipping" zipping (==)
335+ semigroupOps "zipSerially" zipSerially (==)
336− semigroupOps "zippingAsync" zippingAsync (==)
336+ semigroupOps "zipParallely" zipParallely (==)
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
@@ -341,92 +341,92 @@ main = hspec $ do
341 -- XXX applicative with three arguments
341 -- XXX applicative with three arguments
342 prop "serially applicative" $ applicativeOps A.fromFoldable serially (==)
342 prop "serially applicative" $ applicativeOps A.fromFoldable serially (==)
343 prop "serially applicative folded" $ applicativeOps folded serially (==)
343 prop "serially applicative folded" $ applicativeOps folded serially (==)
344− prop "interleaving applicative" $ applicativeOps A.fromFoldable interleaving sortEq
344+ prop "coserially applicative" $ applicativeOps A.fromFoldable coserially sortEq
345− prop "interleaving applicative folded" $ applicativeOps folded interleaving sortEq
345+ prop "coserially applicative folded" $ applicativeOps folded coserially sortEq
346− prop "aparallely applicative" $ applicativeOps A.fromFoldable aparallely sortEq
346+ prop "coparallely applicative" $ applicativeOps A.fromFoldable coparallely sortEq
347− prop "aparallely applicative folded" $ applicativeOps folded aparallely sortEq
347+ prop "coparallely applicative folded" $ applicativeOps folded coparallely sortEq
348 prop "parallely applicative folded" $ applicativeOps folded parallely sortEq
348 prop "parallely applicative folded" $ applicativeOps folded parallely sortEq
349
349
350 describe "Zip operations" $ do
350 describe "Zip operations" $ do
351− prop "zipping applicative" $ zipApplicative A.fromFoldable zipping (==)
351+ prop "zipSerially applicative" $ zipApplicative A.fromFoldable zipSerially (==)
352 -- XXX this hangs
352 -- XXX this hangs
353− -- prop "zippingAsync applicative" $ zipApplicative zippingAsync (==)
353+ -- prop "zipParallely applicative" $ zipApplicative zipParallely (==)
354 prop "zip monadic serially" $ zipMonadic A.fromFoldable serially (==)
354 prop "zip monadic serially" $ zipMonadic A.fromFoldable serially (==)
355 prop "zip monadic serially folded" $ zipMonadic folded serially (==)
355 prop "zip monadic serially folded" $ zipMonadic folded serially (==)
356− prop "zip monadic interleaving" $ zipMonadic A.fromFoldable interleaving (==)
356+ prop "zip monadic coserially" $ zipMonadic A.fromFoldable coserially (==)
357− prop "zip monadic interleaving folded" $ zipMonadic folded interleaving (==)
357+ prop "zip monadic coserially folded" $ zipMonadic folded coserially (==)
358− prop "zip monadic aparallely" $ zipMonadic A.fromFoldable aparallely (==)
358+ prop "zip monadic coparallely" $ zipMonadic A.fromFoldable coparallely (==)
359− prop "zip monadic aparallely folded" $ zipMonadic folded aparallely (==)
359+ prop "zip monadic coparallely folded" $ zipMonadic folded coparallely (==)
360 prop "zip monadic parallely" $ zipMonadic A.fromFoldable parallely (==)
360 prop "zip monadic parallely" $ zipMonadic A.fromFoldable parallely (==)
361 prop "zip monadic parallely folded" $ zipMonadic folded parallely (==)
361 prop "zip monadic parallely folded" $ zipMonadic folded parallely (==)
362
362
363 describe "Monad operations" $ do
363 describe "Monad operations" $ do
364 prop "serially monad then" $ monadThen A.fromFoldable serially (==)
364 prop "serially monad then" $ monadThen A.fromFoldable serially (==)
365− prop "interleaving monad then" $ monadThen A.fromFoldable interleaving sortEq
365+ prop "coserially monad then" $ monadThen A.fromFoldable coserially sortEq
366− prop "aparallely monad then" $ monadThen A.fromFoldable aparallely sortEq
366+ prop "coparallely monad then" $ monadThen A.fromFoldable coparallely sortEq
367 prop "parallely monad then" $ monadThen A.fromFoldable parallely sortEq
367 prop "parallely monad then" $ monadThen A.fromFoldable parallely sortEq
368
368
369 prop "serially monad then folded" $ monadThen folded serially (==)
369 prop "serially monad then folded" $ monadThen folded serially (==)
370− prop "interleaving monad then folded" $ monadThen folded interleaving sortEq
370+ prop "coserially monad then folded" $ monadThen folded coserially sortEq
371− prop "aparallely monad then folded" $ monadThen folded aparallely sortEq
371+ prop "coparallely monad then folded" $ monadThen folded coparallely sortEq
372 prop "parallely monad then folded" $ monadThen folded parallely sortEq
372 prop "parallely monad then folded" $ monadThen folded parallely sortEq
373
373
374 prop "serially monad bind" $ monadBind A.fromFoldable serially (==)
374 prop "serially monad bind" $ monadBind A.fromFoldable serially (==)
375− prop "interleaving monad bind" $ monadBind A.fromFoldable interleaving sortEq
375+ prop "coserially monad bind" $ monadBind A.fromFoldable coserially sortEq
376− prop "aparallely monad bind" $ monadBind A.fromFoldable aparallely sortEq
376+ prop "coparallely monad bind" $ monadBind A.fromFoldable coparallely sortEq
377 prop "parallely monad bind" $ monadBind A.fromFoldable parallely sortEq
377 prop "parallely monad bind" $ monadBind A.fromFoldable parallely sortEq
378
378
379 describe "Stream transform operations" $ do
379 describe "Stream transform operations" $ do
380 transformOps A.fromFoldable "serially" serially (==)
380 transformOps A.fromFoldable "serially" serially (==)
381− transformOps A.fromFoldable "interleaving" interleaving (==)
381+ transformOps A.fromFoldable "coserially" coserially (==)
382− transformOps A.fromFoldable "zipping" zipping (==)
382+ transformOps A.fromFoldable "zipSerially" zipSerially (==)
383− transformOps A.fromFoldable "zippingAsync" zippingAsync (==)
383+ transformOps A.fromFoldable "zipParallely" zipParallely (==)
384− transformOps A.fromFoldable "aparallely" aparallely sortEq
384+ transformOps A.fromFoldable "coparallely" coparallely sortEq
385 transformOps A.fromFoldable "parallely" parallely sortEq
385 transformOps A.fromFoldable "parallely" parallely sortEq
386
386
387 transformOps folded "serially folded" serially (==)
387 transformOps folded "serially folded" serially (==)
388− transformOps folded "interleaving folded" interleaving (==)
388+ transformOps folded "coserially folded" coserially (==)
389− transformOps folded "zipping folded" zipping (==)
389+ transformOps folded "zipSerially folded" zipSerially (==)
390− transformOps folded "zippingAsync folded" zippingAsync (==)
390+ transformOps folded "zipParallely folded" zipParallely (==)
391− transformOps folded "aparallely folded" aparallely sortEq
391+ transformOps folded "coparallely folded" coparallely sortEq
392 transformOps folded "parallely folded" parallely sortEq
392 transformOps folded "parallely folded" parallely sortEq
393
393
394 transformOpsWord8 A.fromFoldable "serially" serially
394 transformOpsWord8 A.fromFoldable "serially" serially
395− transformOpsWord8 A.fromFoldable "interleaving" interleaving
395+ transformOpsWord8 A.fromFoldable "coserially" coserially
396− transformOpsWord8 A.fromFoldable "zipping" zipping
396+ transformOpsWord8 A.fromFoldable "zipSerially" zipSerially
397− transformOpsWord8 A.fromFoldable "zippingAsync" zippingAsync
397+ transformOpsWord8 A.fromFoldable "zipParallely" zipParallely
398− transformOpsWord8 A.fromFoldable "aparallely" aparallely
398+ transformOpsWord8 A.fromFoldable "coparallely" coparallely
399 transformOpsWord8 A.fromFoldable "parallely" parallely
399 transformOpsWord8 A.fromFoldable "parallely" parallely
400
400
401 transformOpsWord8 folded "serially folded" serially
401 transformOpsWord8 folded "serially folded" serially
402− transformOpsWord8 folded "interleaving folded" interleaving
402+ transformOpsWord8 folded "coserially folded" coserially
403− transformOpsWord8 folded "zipping folded" zipping
403+ transformOpsWord8 folded "zipSerially folded" zipSerially
404− transformOpsWord8 folded "zippingAsync folded" zippingAsync
404+ transformOpsWord8 folded "zipParallely folded" zipParallely
405− transformOpsWord8 folded "aparallely folded" aparallely
405+ transformOpsWord8 folded "coparallely folded" coparallely
406 transformOpsWord8 folded "parallely folded" parallely
406 transformOpsWord8 folded "parallely folded" parallely
407
407
408 describe "Stream elimination operations" $ do
408 describe "Stream elimination operations" $ do
409 eliminationOps A.fromFoldable "serially" serially
409 eliminationOps A.fromFoldable "serially" serially
410− eliminationOps A.fromFoldable "interleaving" interleaving
410+ eliminationOps A.fromFoldable "coserially" coserially
411− eliminationOps A.fromFoldable "zipping" zipping
411+ eliminationOps A.fromFoldable "zipSerially" zipSerially
412− eliminationOps A.fromFoldable "zippingAsync" zippingAsync
412+ eliminationOps A.fromFoldable "zipParallely" zipParallely
413− eliminationOps A.fromFoldable "aparallely" aparallely
413+ eliminationOps A.fromFoldable "coparallely" coparallely
414 eliminationOps A.fromFoldable "parallely" parallely
414 eliminationOps A.fromFoldable "parallely" parallely
415
415
416 eliminationOps folded "serially folded" serially
416 eliminationOps folded "serially folded" serially
417− eliminationOps folded "interleaving folded" interleaving
417+ eliminationOps folded "coserially folded" coserially
418− eliminationOps folded "zipping folded" zipping
418+ eliminationOps folded "zipSerially folded" zipSerially
419− eliminationOps folded "zippingAsync folded" zippingAsync
419+ eliminationOps folded "zipParallely folded" zipParallely
420− eliminationOps folded "aparallely folded" aparallely
420+ eliminationOps folded "coparallely folded" coparallely
421 eliminationOps folded "parallely folded" parallely
421 eliminationOps folded "parallely folded" parallely
422
422
423 describe "Stream elimination operations" $ do
423 describe "Stream elimination operations" $ do
424 serialEliminationOps A.fromFoldable "serially" serially
424 serialEliminationOps A.fromFoldable "serially" serially
425− serialEliminationOps A.fromFoldable "interleaving" interleaving
425+ serialEliminationOps A.fromFoldable "coserially" coserially
426− serialEliminationOps A.fromFoldable "zipping" zipping
426+ serialEliminationOps A.fromFoldable "zipSerially" zipSerially
427− serialEliminationOps A.fromFoldable "zippingAsync" zippingAsync
427+ serialEliminationOps A.fromFoldable "zipParallely" zipParallely
428
428
429 serialEliminationOps folded "serially folded" serially
429 serialEliminationOps folded "serially folded" serially
430− serialEliminationOps folded "interleaving folded" interleaving
430+ serialEliminationOps folded "coserially folded" coserially
431− serialEliminationOps folded "zipping folded" zipping
431+ serialEliminationOps folded "zipSerially folded" zipSerially
432− serialEliminationOps folded "zippingAsync folded" zippingAsync
432+ serialEliminationOps folded "zipParallely folded" zipParallely