on master help sign in
Merge pull request #62 from composewell/renaming

Rename stream types for better consistent naming

commitac7a4ab7cf0a7d4d5379872f10dfdbe5ae7f9dd4 authorHarendra Kumar <harendra.kumar@gmail.com> dateWed 18 Apr 2018, 20:47 (8 years ago) parent0631b9d071a90a
13 files changed+465−393
Changelog.md+29−18 benchmark/Main.hs+19−19 examples/loops.hs+4−4 src/Streamly.hs+64−42 src/Streamly/Core.hs+32−28 src/Streamly/Examples/AcidRainGame.hs+1−1 src/Streamly/Examples/ListDirRecursive.hs+3−3 src/Streamly/Examples/MergeSortedStreams.hs+2−2 src/Streamly/Examples/SearchEngineQuery.hs+1−1 src/Streamly/Prelude.hs+11−4 src/Streamly/Streams.hs+198−170 test/Main.hs+42−42 test/Prop.hs+59−59
Changelog.md+29−18
@@ -9,8 +9,8 @@
99 * For `ParallelT`, the `<>` operation now concurrently meges the two streams
1010 in a fairly parallel manner.
1111
12− To adapt to the new changes, replace `<>` with `append` wherever it is used
13− for streams other than `StreamT`.
12+ To adapt to the new changes, replace `<>` with `serial` wherever it is used
13+ for stream types other than `StreamT`.
1414
1515* Change the semantics of `Alternative` instance. The `<|>` operator now has a
1616 different behavior for each type. See the documentation for more details. To
@@ -19,39 +19,50 @@
1919* Stream type now defaults to the `SerialT` type unless explicitly specified
2020 using a type combinator or a monomorphic type. This change reduces puzzling
2121 type errors for beginners. It includes the following two changes:
22− * Change the type of all stream elimination functions to `SerialT`. This
23− makes sure that the stream type is always fixed at all exits.
24− * Change the type combinators to only fix the argument stream type and
25− the resulting stream type remains polymorphic.
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
24+ always fixed at all exits.
25+ * Change the type combinators (e.g. `parallely`) to only fix the argument
26+ stream type and the output stream type remains polymorphic.
2627
27− Stream types may have to be changed or type combinators may have to added or
28− removed to adapt to this change.
28+ Stream types may have to be changed or type combinators may have to be added
29+ or removed to adapt to this change.
2930* Change the type of `foldrM` to make it consistent with `foldrM` in base.
3031
3132### Deprecations
3233* 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`
4034 * `Streaming` to `IsStream`
4135 * `runStreaming` to `runStream`
42− * `<=>` to `interleave`
43− * `<|` to `aparallel`
36+ * `StreamT` to `SerialT`
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`
4446 * `each` to `fromFoldable`
4547 * `scan` to `scanx`
4648 * `foldl` to `foldx`
4749 * `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`
4859
4960### Enhancements
5061* Add the following functions:
5162 * `scanl'` strict left scan
5263 * `foldl'` strict left fold
5364 * `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
5566 * `parallel` run two streams in parallel (replaces `<|>`)
5667
5768## 0.1.2
benchmark/Main.hs+19−19
@@ -41,38 +41,38 @@ main = do
4141 [ bench "function style all serial" $ nfIO streamly_function_style
4242
4343 , bgroup "serial bind"
44− [ bench "serial" $ nfIO (as (A.append))
45− , bench "fair serial" $ nfIO (as (A.interleave))
46− , bench "left parallel" $ nfIO (as (A.aparallel))
44+ [ bench "serial" $ nfIO (as (A.serial))
45+ , bench "fair serial" $ nfIO (as (A.coserial))
46+ , bench "left parallel" $ nfIO (as (A.coparallel))
4747 , bench "fair parallel" $ nfIO (as (A.parallel))
4848 ]
4949
5050 , bgroup "interleaved bind"
51− [ bench "serial" $ nfIO (ai (A.append))
52− , bench "fair serial" $ nfIO (ai (A.interleave))
53− , bench "left parallel" $ nfIO (ai (A.aparallel))
51+ [ bench "serial" $ nfIO (ai (A.serial))
52+ , bench "fair serial" $ nfIO (ai (A.coserial))
53+ , bench "left parallel" $ nfIO (ai (A.coparallel))
5454 , bench "fair parallel" $ nfIO (ai (A.parallel))
5555 ]
5656
5757 , bgroup "async bind"
58− [ bench "serial" $ nfIO (aa (A.append))
59− , bench "fair serial" $ nfIO (aa (A.interleave))
60− , bench "left parallel" $ nfIO (aa (A.aparallel))
58+ [ bench "serial" $ nfIO (aa (A.serial))
59+ , bench "fair serial" $ nfIO (aa (A.coserial))
60+ , bench "left parallel" $ nfIO (aa (A.coparallel))
6161 , bench "fair parallel" $ nfIO (aa (A.parallel))
6262 ]
6363
6464 , bgroup "parallel bind"
65− [ bench "serial" $ nfIO (ap (A.append))
66− , bench "fair serial" $ nfIO (ap (A.interleave))
67− , bench "left parallel" $ nfIO (ap (A.aparallel))
65+ [ bench "serial" $ nfIO (ap (A.serial))
66+ , bench "fair serial" $ nfIO (ap (A.coserial))
67+ , bench "left parallel" $ nfIO (ap (A.coparallel))
6868 , bench "fair parallel" $ nfIO (ap (A.parallel))
6969 ]
7070
7171 -- Benchmark smallest possible actions composed together
7272 , bgroup "serial bind nil"
73− [ bench "serial" $ nfIO (streamly_nil (A.append))
74− , bench "fair serial" $ nfIO (streamly_nil (A.interleave))
75− , bench "left parallel" $ nfIO (streamly_nil (A.aparallel))
73+ [ bench "serial" $ nfIO (streamly_nil (A.serial))
74+ , bench "fair serial" $ nfIO (streamly_nil (A.coserial))
75+ , bench "left parallel" $ nfIO (streamly_nil (A.coparallel))
7676 , bench "fair parallel" $ nfIO (streamly_nil (A.parallel))
7777 ]
7878 ]
@@ -141,15 +141,15 @@ streamly_serial = streamly_basic (A.toList . A.serially)
141141
142142{-# INLINE streamly_interleaved #-}
143143streamly_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)
145145 -> IO Int
146−streamly_interleaved = streamly_basic (A.toList . A.interleaving)
146+streamly_interleaved = streamly_basic (A.toList . A.coserially)
147147
148148{-# INLINE streamly_async #-}
149149streamly_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)
151151 -> IO Int
152−streamly_async = streamly_basic (A.toList . A.aparallely)
152+streamly_async = streamly_basic (A.toList . A.coparallely)
153153
154154{-# INLINE streamly_parallel #-}
155155streamly_parallel
examples/loops.hs+4−4
@@ -24,9 +24,9 @@ main = do
2424 x <- loopHeadA 0
2525 liftIO $ print (x :: Int)
2626
27− putStrLn $ "\ninterleave:\n"
27+ putStrLn $ "\ncoserial:\n"
2828 runStream $ do
29− x <- (return 0 <> return 1) `interleave` (return 100 <> return 101)
29+ x <- (return 0 <> return 1) `coserial` (return 100 <> return 101)
3030 liftIO $ print (x :: Int)
3131
3232 putStrLn $ "\nParallel interleave:\n"
@@ -71,12 +71,12 @@ main = do
7171 loopTailA :: Int -> SerialT IO Int
7272 loopTailA x = do
7373 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)
7575
7676 loopHeadA :: Int -> SerialT IO Int
7777 loopHeadA x = do
7878 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
8080
8181-------------------------------------------------------------------------------
8282-- Parallel (fairly scheduled, multi-threaded) stream generator loops
src/Streamly.hs+64−42
@@ -15,45 +15,48 @@ module Streamly
1515 -- * Overview
1616 -- $overview
1717
18− MonadAsync
18+ MonadParallel
1919 , IsStream
2020
21− -- * General Stream Styles
22− -- $product
21+ -- * Serial Streams
22+ -- $serial
2323 , SerialT
24− , InterleavedT
25− , AParallelT
24+ , CoserialT
25+
26+ -- * Parallel Streams
27+ -- $parallel
28+ , CoparallelT
2629 , ParallelT
2730
28− -- * Zip Style Streams
31+ -- * Zipping Streams
2932 -- $zipping
3033 , ZipSerial
31− , ZipAsync
32−
33− -- * Polymorphic Sum Operations
34− -- $sum
35− , append
36− , interleave
37− , aparallel
38− , parallel
39−
40− -- * Transformation
41− , async
34+ , ZipParallel
4235
4336 -- * Stream Type Adapters
4437 -- $adapters
4538 , serially
46− , interleaving
47− , aparallely
39+ , coserially
40+ , coparallely
4841 , parallely
49− , zipping
50− , zippingAsync
42+ , zipSerially
43+ , zipParallely
5144 , adapt
5245
5346 -- * Running Streams
5447 , runStream
5548
56− -- * Fold Utilities
49+ -- * Transformation
50+ , async
51+
52+ -- * Polymorphic Sum Operations
53+ -- $sum
54+ , serial
55+ , coserial
56+ , coparallel
57+ , parallel
58+
59+ -- * Polymorphic Fold Utilities
5760 -- $foldutils
5861 , foldWith
5962 , foldMapWith
@@ -68,6 +71,7 @@ module Streamly
6871 , MonadTrans (..)
6972
7073 -- * Deprecated
74+ , MonadAsync
7175 , Streaming
7276 , runStreaming
7377 , runStreamT
@@ -77,9 +81,14 @@ module Streamly
7781 , runAsyncT
7882 , runZipStream
7983 , StreamT
84+ , InterleavedT
8085 , AsyncT
8186 , ZipStream
87+ , ZipAsync
88+ , interleaving
8289 , asyncly
90+ , zipping
91+ , zippingAsync
8392 , (<=>)
8493 , (<|)
8594 )
@@ -126,28 +135,28 @@ import Control.Monad.Trans.Class (MonadTrans (..))
126135
127136-- $overview
128137--
129−-- Streamly provides six distinct stream types i.e. 'SerialT', 'InterleavedT',
130−-- 'AParallelT' and 'ParallelT', 'ZipStream' and 'ZipAsync', each representing a
138+-- Streamly provides six distinct stream types i.e. 'SerialT', 'CoserialT',
139+-- 'CoparallelT' and 'ParallelT', 'ZipSerial' and 'ZipParallel', each representing a
131140-- stream of elements. All these types have the same underlying representation
132141-- and can be adapted from one to another using type adaptor combinators
133142-- described later. Each of these types belongs to the 'IsStream' type class
134143-- which helps converting the specific type to and from the underlying generic
135144-- stream type.
136145--
137−-- The types 'SerialT', 'InterleavedT', 'AParallelT' and 'ParallelT' are 'Monad'
146+-- The types 'SerialT', 'CoserialT', 'CoparallelT' and 'ParallelT' are 'Monad'
138147-- transformers with the monadic bind operation combining streams in a product
139148-- style in much the same way as a list monad or a list transformer i.e. each
140149-- element from one stream is combined with every element of the other stream.
141150-- However, the applicative and monadic composition of these types differ in
142151-- terms of the ordering and time sequence in which the elements from two
143−-- streams are combined. 'SerialT' and 'InterleavedT' compose streams serially
144−-- whereas 'AParallelT' and 'ParallelT' are their concurrent counterparts. See the
152+-- streams are combined. 'SerialT' and 'CoserialT' compose streams serially
153+-- whereas 'CoparallelT' and 'ParallelT' are their concurrent counterparts. See the
145154-- documentation of the respective types for more details.
146155--
147−-- The types 'ZipStream' and 'ZipAsync' provide 'Applicative' instances to zip
156+-- The types 'ZipSerial' and 'ZipParallel' provide 'Applicative' instances to zip
148157-- 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
150−-- being zipped serially whereas 'ZipAsync' produces both the elements being
158+-- corresponding element in the other stream. 'ZipSerial' generates the streams
159+-- being zipped serially whereas 'ZipParallel' produces both the elements being
151160-- zipped concurrently.
152161--
153162-- 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 (..))
156165-- (concurrent or serial) in which the elements in the resulting stream are
157166-- produced depends on the type of the stream.
158167--
159−-- Concurrent composition types 'AParallelT', 'ParallelT', 'ZipAsync' require the
160−-- underlying monad of the streaming monad transformer to be 'MonadAsync'.
161−--
162168-- For more details please see the "Streamly.Tutorial" and "Streamly.Examples"
163169-- (the latter is available only when built with the 'examples' build flag).
164170
165171-- A simple inline example here illustrating applicative, monad and alternative
166172-- compositions.
167173
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
169184--
170−-- Streams that compose serially or non-concurrently come in two flavors i.e.
171−-- 'SerialT' and 'InterleavedT'. Both of these serial flavors have
172−-- corresponding concurrent equivalents, those are 'AParallelT' and 'ParallelT'
173−-- respectively.
185+-- Parallel streams compose parallely or concurrently. In a composed stream, at
186+-- any point of time more than one stream can run concurrently and yield
187+-- elements. The two parallel types 'ParallelT' and 'CoparallelT' differ in how
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.
174195
175196-- $zipping
176197--
177−-- 'ZipStream' and 'ZipAsync', provide 'Applicative' instances for zipping the
198+-- 'ZipSerial' and 'ZipParallel', provide 'Applicative' instances for zipping the
178199-- corresponding elements of two streams together. Note that these types are
179200-- not monads.
180201
@@ -193,7 +214,7 @@ import Control.Monad.Trans.Class (MonadTrans (..))
193214-- To adapt from one monomorphic type (e.g. 'ParallelT') to another monomorphic
194215-- type (e.g. 'SerialT') use the 'adapt' combinator. To give a polymorphic code
195216-- 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
197218-- cannot adapt polymorphic code to polymorphic code, as it would not know
198219-- which specific type you are converting from or to. If you see a an
199220-- @ambiguous type variable@ error then most likely you are using 'adapt'
@@ -202,5 +223,6 @@ import Control.Monad.Trans.Class (MonadTrans (..))
202223
203224-- $foldutils
204225--
205−-- These are some convenience functions to fold any 'Foldable' container using
206−-- one of the sum composition operators to convert it into a streamly stream.
226+-- These are variants of standard 'Foldable' fold functions that use a
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 @@
1818--
1919module Streamly.Core
2020 (
21− MonadAsync
21+ MonadParallel
22+ , MonadAsync -- deprecated
2223
2324 -- * Streams
2425 , Stream (..)
@@ -29,9 +30,9 @@ module Streamly.Core
2930 , nil
3031
3132 -- * Semigroup Style Composition
32− , append
33− , interleave
34− , aparallel
33+ , serial
34+ , coserial
35+ , coparallel
3536 , parallel
3637
3738 -- * Alternative
@@ -213,10 +214,13 @@ newtype Stream m a =
213214 -> m r
214215 }
215216
216−-- | A monad that can perform asynchronous/concurrent IO operations. Streams
217+-- | A monad that can perform concurrent or parallel IO operations. Streams
217218-- that can be composed concurrently require the underlying monad to be
218−-- 'MonadAsync'.
219−type MonadAsync m = (MonadIO m, MonadBaseControl IO m, MonadThrow m)
219+-- 'MonadParallel'.
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
220224
221225cons :: a -> Maybe (Stream m a) -> Stream m a
222226cons a r = Stream $ \_ _ yld -> yld a r
@@ -242,8 +246,8 @@ nil = Stream $ \_ stp _ -> stp
242246
243247-- | Concatenates two streams sequentially i.e. the first stream is
244248-- exhausted completely before yielding any element from the second stream.
245−append :: Stream m a -> Stream m a -> Stream m a
246−append m1 m2 = go m1
249+serial :: Stream m a -> Stream m a -> Stream m a
250+serial m1 m2 = go m1
247251 where
248252 go (Stream m) = Stream $ \_ stp yld ->
249253 let stop = (runStream m2) Nothing stp yld
@@ -252,7 +256,7 @@ append m1 m2 = go m1
252256 in m Nothing stop yield
253257
254258instance Semigroup (Stream m a) where
255− (<>) = append
259+ (<>) = serial
256260
257261------------------------------------------------------------------------------
258262-- Monoid
@@ -266,11 +270,11 @@ instance Monoid (Stream m a) where
266270-- Interleave
267271------------------------------------------------------------------------------
268272
269−interleave :: Stream m a -> Stream m a -> Stream m a
270−interleave m1 m2 = Stream $ \_ stp yld -> do
273+coserial :: Stream m a -> Stream m a -> Stream m a
274+coserial m1 m2 = Stream $ \_ stp yld -> do
271275 let stop = (runStream m2) Nothing stp yld
272276 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))
274278 (runStream m1) Nothing stop yield
275279
276280------------------------------------------------------------------------------
@@ -377,7 +381,7 @@ handleChildException sv e = do
377381 send sv (ChildStop tid (Just e))
378382
379383{-# NOINLINE pushWorker #-}
380−pushWorker :: MonadAsync m => SVar m a -> m ()
384+pushWorker :: MonadParallel m => SVar m a -> m ()
381385pushWorker sv =
382386 doFork (runqueue sv) (handleChildException sv) >>= addThread sv
383387
@@ -386,7 +390,7 @@ pushWorker sv =
386390-- block or make it go away entirely, depending on the number of workers and
387391-- the type of the queue.
388392{-# INLINE sendWorkerWait #-}
389−sendWorkerWait :: MonadAsync m => SVar m a -> m ()
393+sendWorkerWait :: MonadParallel m => SVar m a -> m ()
390394sendWorkerWait sv = do
391395 case svarStyle sv of
392396 SVarStyle _ LIFO -> liftIO $ threadDelay 200
@@ -401,7 +405,7 @@ sendWorkerWait sv = do
401405
402406-- | Pull a stream from an SVar.
403407{-# NOINLINE fromStreamVar #-}
404−fromStreamVar :: MonadAsync m => SVar m a -> Stream m a
408+fromStreamVar :: MonadParallel m => SVar m a -> Stream m a
405409fromStreamVar sv = Stream $ \_ stp yld -> do
406410 -- XXX if reading the IORef is costly we can use a flag in the SVar to
407411 -- indicate we are done.
@@ -479,7 +483,7 @@ getLifoSVar ctype = do
479483 in return sv
480484
481485-- | Create a new empty SVar.
482−newEmptySVar :: MonadAsync m => SVarStyle -> m (SVar m a)
486+newEmptySVar :: MonadParallel m => SVarStyle -> m (SVar m a)
483487newEmptySVar style = do
484488 liftIO $
485489 case style of
@@ -487,7 +491,7 @@ newEmptySVar style = do
487491 SVarStyle _ LIFO -> getLifoSVar style
488492
489493-- | 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)
491495newStreamVar1 style m = do
492496 sv <- newEmptySVar style
493497 -- Note: We must have all the work on the queue before sending the
@@ -498,7 +502,7 @@ newStreamVar1 style m = do
498502 return sv
499503
500504-- | Create a new SVar and enqueue two stream computations on it.
501−newStreamVar2 :: MonadAsync m
505+newStreamVar2 :: MonadParallel m
502506 => SVarStyle -> Stream m a -> Stream m a -> m (SVar m a)
503507newStreamVar2 style m1 m2 = do
504508 -- Note: We must have all the work on the queue before sending the
@@ -519,7 +523,7 @@ newStreamVar2 style m1 m2 = do
519523
520524-- | Write a stream to an 'SVar' in a non-blocking manner. The stream can then
521525-- 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 ()
523527toStreamVar sv m = do
524528 liftIO $ (enqueue sv) m
525529 done <- allThreadsDone sv
@@ -561,7 +565,7 @@ toStreamVar sv m = do
561565-- just the number of CPUs.
562566
563567{-# NOINLINE withNewSVar2 #-}
564−withNewSVar2 :: MonadAsync m
568+withNewSVar2 :: MonadParallel m
565569 => SVarStyle -> Stream m a -> Stream m a -> Stream m a
566570withNewSVar2 style m1 m2 = Stream $ \_ stp yld -> do
567571 sv <- newStreamVar2 style m1 m2
@@ -596,7 +600,7 @@ withNewSVar2 style m1 m2 = Stream $ \_ stp yld -> do
596600-- of the two.
597601--
598602{-# INLINE joinStreamVar2 #-}
599−joinStreamVar2 :: MonadAsync m
603+joinStreamVar2 :: MonadParallel m
600604 => SVarStyle -> Stream m a -> Stream m a -> Stream m a
601605joinStreamVar2 style m1 m2 = Stream $ \st stp yld ->
602606 case st of
@@ -608,12 +612,12 @@ joinStreamVar2 style m1 m2 = Stream $ \st stp yld ->
608612-- Semigroup and Monoid style compositions for parallel actions
609613------------------------------------------------------------------------------
610614
611−{-# INLINE aparallel #-}
612−aparallel :: MonadAsync m => Stream m a -> Stream m a -> Stream m a
613−aparallel = joinStreamVar2 (SVarStyle Disjunction LIFO)
615+{-# INLINE coparallel #-}
616+coparallel :: MonadParallel m => Stream m a -> Stream m a -> Stream m a
617+coparallel = joinStreamVar2 (SVarStyle Disjunction LIFO)
614618
615619{-# 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
617621parallel = joinStreamVar2 (SVarStyle Disjunction FIFO)
618622
619623-------------------------------------------------------------------------------
@@ -647,11 +651,11 @@ alt m1 m2 = Stream $ \_ stp yld ->
647651 yield = yld
648652 in runStream m1 Nothing stop yield
649653
650−instance MonadAsync m => Alternative (Stream m) where
654+instance MonadParallel m => Alternative (Stream m) where
651655 empty = nil
652656 (<|>) = alt
653657
654−instance MonadAsync m => MonadPlus (Stream m) where
658+instance MonadParallel m => MonadPlus (Stream m) where
655659 mzero = nil
656660 mplus = (<|>)
657661
src/Streamly/Examples/AcidRainGame.hs+1−1
@@ -26,7 +26,7 @@ userAction = cycle1 $ liftIO askUser
2626acidRain :: MonadIO m => SerialT m Event
2727acidRain = cycle1 $ liftIO (threadDelay 1000000) >> return (Harm 1)
2828
29−game :: (MonadAsync m, MonadState Int m) => SerialT m ()
29+game :: (MonadParallel m, MonadState Int m) => SerialT m ()
3030game = do
3131 event <- userAction `parallel` acidRain
3232 case event of
src/Streamly/Examples/ListDirRecursive.hs+3−3
@@ -3,15 +3,15 @@ module Streamly.Examples.ListDirRecursive where
33import Control.Monad.IO.Class (liftIO)
44import Path.IO (listDir, getCurrentDir)
55import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
6−import Streamly (runStream, aparallely)
6+import Streamly (runStream, coparallely)
77
88-- | This example demonstrates that there is little difference between regular
99-- 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.
1111listDirRecursive :: IO ()
1212listDirRecursive = do
1313 hSetBuffering stdout LineBuffering
14− runStream . aparallely $ getCurrentDir >>= readdir
14+ runStream . coparallely $ getCurrentDir >>= readdir
1515 where readdir d = do
1616 (ds, fs) <- liftIO $ listDir d
1717 liftIO $ mapM_ putStrLn $ map show fs ++ map show ds
src/Streamly/Examples/MergeSortedStreams.hs+2−2
@@ -14,14 +14,14 @@ getSorted = do
1414 let ls = take 100000 (randoms g) :: [Word16]
1515 foldMapWith (<>) return (sort ls)
1616
17−mergeAsync :: (Ord a, MonadAsync m)
17+mergeAsync :: (Ord a, MonadParallel m)
1818 => SerialT m a -> SerialT m a -> SerialT m a
1919mergeAsync a b = do
2020 x <- lift $ async a
2121 y <- lift $ async b
2222 merge x y
2323
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
2525merge a b = do
2626 a1 <- lift $ A.uncons a
2727 case a1 of
src/Streamly/Examples/SearchEngineQuery.hs+1−1
@@ -10,7 +10,7 @@ searchEngineQuery = do
1010 runStream . parallely $ google <> bing <> duckduckgo
1111
1212 putStrLn "\nUsing parallel applicative zip"
13− runStream . zippingAsync $ (,,) <$> google <*> bing <*> duckduckgo
13+ runStream . zipParallely $ (,,) <$> google <*> bing <*> duckduckgo
1414
1515 where
1616 get :: IsStream t => String -> t IO ()
src/Streamly/Prelude.hs+11−4
@@ -72,8 +72,8 @@ module Streamly.Prelude
7272 -- * Zipping
7373 , zipWith
7474 , zipWithM
75− , zipAsyncWith
76− , zipAsyncWithM
75+ , zipParallelWith
76+ , zipParallelWithM
7777
7878 -- * IO
7979 , fromHandle
@@ -84,6 +84,8 @@ module Streamly.Prelude
8484 , scan
8585 , foldl
8686 , foldlM
87+ , zipAsyncWith
88+ , zipAsyncWithM
8789 )
8890where
8991
@@ -569,9 +571,14 @@ zipWithM f m1 m2 = fromStream $ go (toStream m1) (toStream m2)
569571
570572-- | Zip two streams asyncly (i.e. both the elements being zipped are generated
571573-- concurrently) using a monadic zipping function.
572−zipAsyncWithM :: (IsStream t, MonadAsync m)
574+zipParallelWithM :: (IsStream t, MonadParallel m)
573575 => (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
575577 ma <- async m1
576578 mb <- async m2
577579 (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
2121 (
2222 IsStream (..)
2323 , Streaming -- deprecated
24− , MonadAsync
24+ , MonadParallel
25+ , S.MonadAsync -- deprecated
2526
2627 -- * SVars
2728 , SVarSched (..)
@@ -48,9 +49,9 @@ module Streamly.Streams
4849 , async
4950
5051 -- * Merging Streams
51− , append
52− , interleave
53− , aparallel
52+ , serial
53+ , coserial
54+ , coparallel
5455 , parallel
5556 , (<=>) --deprecated
5657 , (<|) --deprecated
@@ -58,22 +59,27 @@ module Streamly.Streams
5859 -- * Stream Styles
5960 , SerialT
6061 , StreamT -- deprecated
61− , InterleavedT
62− , AParallelT
62+ , CoserialT
63+ , InterleavedT -- deprecated
64+ , CoparallelT
6365 , AsyncT -- deprecated
6466 , ParallelT
6567 , ZipSerial
6668 , ZipStream -- deprecated
67− , ZipAsync
69+ , ZipParallel
70+ , ZipAsync -- deprecated
6871
6972 -- * Type Adapters
7073 , serially
71− , interleaving
72− , aparallely
74+ , coserially
75+ , interleaving -- deprecated
76+ , coparallely
7377 , asyncly -- deprecated
7478 , parallely
75− , zipping
76− , zippingAsync
79+ , zipSerially
80+ , zipping -- deprecated
81+ , zipParallely
82+ , zippingAsync -- deprecated
7783 , adapt
7884
7985 -- * Running Streams
@@ -86,10 +92,10 @@ module Streamly.Streams
8692
8793 -- * Zipping
8894 , zipWith
89− , zipAsyncWith
95+ , zipParallelWith
96+ , zipAsyncWith -- deprecated
9097
9198 -- * Fold Utilities
92− -- $foldutils
9399 , foldWith
94100 , foldMapWith
95101 , forEachWith
@@ -107,7 +113,7 @@ import Control.Monad.State.Class (MonadState(..))
107113import Control.Monad.Trans.Class (MonadTrans)
108114import Data.Semigroup (Semigroup(..))
109115import Prelude hiding (zipWith)
110−import Streamly.Core ( MonadAsync, Stream(Stream)
116+import Streamly.Core ( MonadParallel, Stream(Stream)
111117 , SVar, SVarStyle(..)
112118 , SVarTag(..), SVarSched(..))
113119import qualified Streamly.Core as S
@@ -199,7 +205,7 @@ fromCallback :: IsStream t => (forall r. (a -> m r) -> m r) -> t m a
199205fromCallback k = fromStream $ Stream $ \_ _ yld -> k (\a -> yld a Nothing)
200206
201207-- | 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
203209fromSVar sv = fromStream $ S.fromStreamVar sv
204210
205211------------------------------------------------------------------------------
@@ -216,7 +222,9 @@ streamFold sv step blank m =
216222 yield a (Just x) = step a (Just (fromStream x))
217223 in (S.runStream (toStream m)) sv blank yield
218224
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'@.
220228runStream :: Monad m => SerialT m a -> m ()
221229runStream m = go (toStream m)
222230 where
@@ -233,7 +241,7 @@ runStreaming = runStream . adapt
233241
234242-- | Write a stream to an 'SVar' in a non-blocking manner. The stream can then
235243-- 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 ()
237245toSVar sv m = S.toStreamVar sv (toStream m)
238246
239247------------------------------------------------------------------------------
@@ -247,7 +255,7 @@ toSVar sv m = S.toStreamVar sv (toStream m)
247255-- not drained fully we may have a thread blocked forever and once exhausted it
248256-- will always return 'empty'.
249257
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)
251259async m = do
252260 sv <- S.newStreamVar1 (SVarStyle Disjunction LIFO) (toStream m)
253261 return $ fromSVar sv
@@ -309,8 +317,8 @@ async m = do
309317newtype SerialT m a = SerialT {getSerialT :: Stream m a}
310318 deriving (Semigroup, Monoid, MonadTrans, MonadIO, MonadThrow)
311319
312−deriving instance MonadAsync m => Alternative (SerialT m)
313−deriving instance MonadAsync m => MonadPlus (SerialT m)
320+deriving instance MonadParallel m => Alternative (SerialT m)
321+deriving instance MonadParallel m => MonadPlus (SerialT m)
314322deriving instance (MonadBase b m, Monad m) => MonadBase b (SerialT m)
315323deriving instance MonadError e m => MonadError e (SerialT m)
316324deriving instance MonadReader r m => MonadReader r (SerialT m)
@@ -336,9 +344,9 @@ type StreamT = SerialT
336344-- | Polymorphic version of the 'Semigroup' operation '<>' of 'SerialT'.
337345-- Appends two streams sequentially, yielding all elements from the first
338346-- stream, and then all elements from the second stream.
339−{-# INLINE append #-}
340−append :: IsStream t => t m a -> t m a -> t m a
341−append m1 m2 = fromStream $ S.append (toStream m1) (toStream m2)
347+{-# INLINE serial #-}
348+serial :: IsStream t => t m a -> t m a -> t m a
349+serial m1 m2 = fromStream $ S.serial (toStream m1) (toStream m2)
342350
343351------------------------------------------------------------------------------
344352-- Monad
@@ -416,10 +424,10 @@ instance (Monad m, Floating a) => Floating (SerialT m a) where
416424 logBase = liftA2 logBase
417425
418426------------------------------------------------------------------------------
419−-- InterleavedT
427+-- CoserialT
420428------------------------------------------------------------------------------
421429
422−-- | The 'Semigroup' instance of 'InterleavedT' interleaves two streams,
430+-- | The 'Semigroup' instance of 'CoserialT' interleaves two streams,
423431-- yielding one element from each stream alternately.
424432--
425433-- @
@@ -449,48 +457,51 @@ instance (Monad m, Floating a) => Floating (SerialT m a) where
449457-- Note that interleaving composition can only combine a finite number of
450458-- streams as it needs to retain state for each unfinished stream.
451459--
452−newtype InterleavedT m a = InterleavedT {getInterleavedT :: Stream m a}
460+newtype CoserialT m a = CoserialT {getCoserialT :: Stream m a}
453461 deriving (Monoid, MonadTrans, MonadIO, MonadThrow)
454462
455−deriving instance MonadAsync m => Alternative (InterleavedT m)
456−deriving instance MonadAsync m => MonadPlus (InterleavedT m)
457−deriving instance (MonadBase b m, Monad m) => MonadBase b (InterleavedT m)
458−deriving instance MonadError e m => MonadError e (InterleavedT m)
459−deriving instance MonadReader r m => MonadReader r (InterleavedT m)
460−deriving instance MonadState s m => MonadState s (InterleavedT m)
463+deriving instance MonadParallel m => Alternative (CoserialT m)
464+deriving instance MonadParallel m => MonadPlus (CoserialT m)
465+deriving instance (MonadBase b m, Monad m) => MonadBase b (CoserialT m)
466+deriving instance MonadError e m => MonadError e (CoserialT m)
467+deriving instance MonadReader r m => MonadReader r (CoserialT m)
468+deriving instance MonadState s m => MonadState s (CoserialT m)
461469
462−instance IsStream InterleavedT where
463− toStream = getInterleavedT
464− fromStream = InterleavedT
470+{-# DEPRECATED InterleavedT "Please use 'CoserialT' instead." #-}
471+type InterleavedT = CoserialT
472+
473+instance IsStream CoserialT where
474+ toStream = getCoserialT
475+ fromStream = CoserialT
465476
466477------------------------------------------------------------------------------
467478-- Semigroup
468479------------------------------------------------------------------------------
469480
470−-- | Polymorphic version of the 'Semigroup' operation '<>' of 'InterleavedT'.
481+-- | Polymorphic version of the 'Semigroup' operation '<>' of 'CoserialT'.
471482-- Interleaves two streams, yielding one element from each stream alternately.
472−{-# INLINE interleave #-}
473−interleave :: IsStream t => t m a -> t m a -> t m a
474−interleave m1 m2 = fromStream $ S.interleave (toStream m1) (toStream m2)
483+{-# INLINE coserial #-}
484+coserial :: IsStream t => t m a -> t m a -> t m a
485+coserial m1 m2 = fromStream $ S.coserial (toStream m1) (toStream m2)
475486
476−instance Semigroup (InterleavedT m a) where
477− (<>) = interleave
487+instance Semigroup (CoserialT m a) where
488+ (<>) = coserial
478489
479490infixr 5 <=>
480491
481−-- | Same as 'interleave'.
482−{-# Deprecated (<=>) "Please use '<>' of InterleavedT or 'interleave' instead." #-}
492+-- | Same as 'coserial'.
493+{-# DEPRECATED (<=>) "Please use 'coserial' instead." #-}
483494{-# INLINE (<=>) #-}
484495(<=>) :: IsStream t => t m a -> t m a -> t m a
485−(<=>) = interleave
496+(<=>) = coserial
486497
487498------------------------------------------------------------------------------
488499-- Monad
489500------------------------------------------------------------------------------
490501
491−instance Monad m => Monad (InterleavedT m) where
502+instance Monad m => Monad (CoserialT m) where
492503 return = pure
493− (InterleavedT (Stream m)) >>= f = InterleavedT $ Stream $ \_ stp yld ->
504+ (CoserialT (Stream m)) >>= f = CoserialT $ Stream $ \_ stp yld ->
494505 let run x = (S.runStream x) Nothing stp yld
495506 yield a Nothing = run $ toStream (f a)
496507 yield a (Just r) = run $ toStream $ f a <> (fromStream r >>= f)
@@ -500,26 +511,26 @@ instance Monad m => Monad (InterleavedT m) where
500511-- Applicative
501512------------------------------------------------------------------------------
502513
503−instance Monad m => Applicative (InterleavedT m) where
504− pure a = InterleavedT $ S.cons a Nothing
514+instance Monad m => Applicative (CoserialT m) where
515+ pure a = CoserialT $ S.cons a Nothing
505516 (<*>) = ap
506517
507518------------------------------------------------------------------------------
508519-- Functor
509520------------------------------------------------------------------------------
510521
511−instance Monad m => Functor (InterleavedT m) where
512− fmap f (InterleavedT (Stream m)) = InterleavedT $ Stream $ \_ stp yld ->
522+instance Monad m => Functor (CoserialT m) where
523+ fmap f (CoserialT (Stream m)) = CoserialT $ Stream $ \_ stp yld ->
513524 let yield a Nothing = yld (f a) Nothing
514525 yield a (Just r) =
515− yld (f a) (Just (getInterleavedT (fmap f (InterleavedT r))))
526+ yld (f a) (Just (getCoserialT (fmap f (CoserialT r))))
516527 in m Nothing stp yield
517528
518529------------------------------------------------------------------------------
519530-- Num
520531------------------------------------------------------------------------------
521532
522−instance (Monad m, Num a) => Num (InterleavedT m a) where
533+instance (Monad m, Num a) => Num (CoserialT m a) where
523534 fromInteger n = pure (fromInteger n)
524535
525536 negate = fmap negate
@@ -530,14 +541,14 @@ instance (Monad m, Num a) => Num (InterleavedT m a) where
530541 (*) = liftA2 (*)
531542 (-) = liftA2 (-)
532543
533−instance (Monad m, Fractional a) => Fractional (InterleavedT m a) where
544+instance (Monad m, Fractional a) => Fractional (CoserialT m a) where
534545 fromRational n = pure (fromRational n)
535546
536547 recip = fmap recip
537548
538549 (/) = liftA2 (/)
539550
540−instance (Monad m, Floating a) => Floating (InterleavedT m a) where
551+instance (Monad m, Floating a) => Floating (CoserialT m a) where
541552 pi = pure pi
542553
543554 exp = fmap exp
@@ -560,7 +571,7 @@ instance (Monad m, Floating a) => Floating (InterleavedT m a) where
560571 logBase = liftA2 logBase
561572
562573------------------------------------------------------------------------------
563−-- AParallelT
574+-- CoparallelT
564575------------------------------------------------------------------------------
565576
566577-- | 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
570581-- enough for the consumer.
571582--
572583-- @
573−-- main = ('toList' . 'aparallely' $ (fromFoldable [1,2]) \<> (fromFoldable [3,4])) >>= print
584+-- main = ('toList' . 'coparallely' $ (fromFoldable [1,2]) \<> (fromFoldable [3,4])) >>= print
574585-- @
575586-- @
576587-- [1,2,3,4]
@@ -585,7 +596,7 @@ instance (Monad m, Floating a) => Floating (InterleavedT m a) where
585596-- import "Streamly"
586597-- import Control.Concurrent
587598--
588−-- main = 'runStream' . 'aparallely' $ do
599+-- main = 'runStream' . 'coparallely' $ do
589600-- n <- return 3 \<\> return 2 \<\> return 1
590601-- liftIO $ do
591602-- threadDelay (n * 1000000)
@@ -602,45 +613,45 @@ instance (Monad m, Floating a) => Floating (InterleavedT m a) where
602613-- Note that this composition can be used to combine infinite number of streams
603614-- as it explores only a bounded number of streams at a time.
604615--
605−newtype AParallelT m a = AParallelT {getAParallelT :: Stream m a}
616+newtype CoparallelT m a = CoparallelT {getCoparallelT :: Stream m a}
606617 deriving (MonadTrans)
607618
608−deriving instance MonadAsync m => Monoid (AParallelT m a)
609−deriving instance MonadAsync m => Alternative (AParallelT m)
610−deriving instance MonadAsync m => MonadPlus (AParallelT m)
611−deriving instance MonadAsync m => MonadIO (AParallelT m)
612−deriving instance MonadAsync m => MonadThrow (AParallelT m)
613−deriving instance (MonadBase b m, MonadAsync m) => MonadBase b (AParallelT m)
614−deriving instance (MonadError e m, MonadAsync m) => MonadError e (AParallelT m)
615−deriving instance (MonadReader r m, MonadAsync m) => MonadReader r (AParallelT m)
616−deriving instance (MonadState s m, MonadAsync m) => MonadState s (AParallelT m)
619+deriving instance MonadParallel m => Monoid (CoparallelT m a)
620+deriving instance MonadParallel m => Alternative (CoparallelT m)
621+deriving instance MonadParallel m => MonadPlus (CoparallelT m)
622+deriving instance MonadParallel m => MonadIO (CoparallelT m)
623+deriving instance MonadParallel m => MonadThrow (CoparallelT m)
624+deriving instance (MonadBase b m, MonadParallel m) => MonadBase b (CoparallelT m)
625+deriving instance (MonadError e m, MonadParallel m) => MonadError e (CoparallelT m)
626+deriving instance (MonadReader r m, MonadParallel m) => MonadReader r (CoparallelT m)
627+deriving instance (MonadState s m, MonadParallel m) => MonadState s (CoparallelT m)
617628
618−{-# DEPRECATED AsyncT "Please use 'AParallelT' instead." #-}
619−type AsyncT = AParallelT
629+{-# DEPRECATED AsyncT "Please use 'CoparallelT' instead." #-}
630+type AsyncT = CoparallelT
620631
621−instance IsStream AParallelT where
622− toStream = getAParallelT
623− fromStream = AParallelT
632+instance IsStream CoparallelT where
633+ toStream = getCoparallelT
634+ fromStream = CoparallelT
624635
625636------------------------------------------------------------------------------
626637-- Semigroup
627638------------------------------------------------------------------------------
628639
629−-- | Polymorphic version of the 'Semigroup' operation '<>' of 'AParallelT', but
640+-- | Polymorphic version of the 'Semigroup' operation '<>' of 'CoparallelT', but
630641-- polymorphic. Merges two streams possibly concurrently, preferring the
631642-- elements from the left one when available.
632−{-# INLINE aparallel #-}
633−aparallel :: (IsStream t, MonadAsync m) => t m a -> t m a -> t m a
634−aparallel m1 m2 = fromStream $ S.aparallel (toStream m1) (toStream m2)
643+{-# INLINE coparallel #-}
644+coparallel :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
645+coparallel m1 m2 = fromStream $ S.coparallel (toStream m1) (toStream m2)
635646
636−instance MonadAsync m => Semigroup (AParallelT m a) where
637− (<>) = aparallel
647+instance MonadParallel m => Semigroup (CoparallelT m a) where
648+ (<>) = coparallel
638649
639−-- | Same as 'aparallel'.
640−{-# DEPRECATED (<|) "Please use 'aparallel' instead." #-}
650+-- | Same as 'coparallel'.
651+{-# DEPRECATED (<|) "Please use 'coparallel' instead." #-}
641652{-# INLINE (<|) #-}
642−(<|) :: (IsStream t, MonadAsync m) => t m a -> t m a -> t m a
643−(<|) = aparallel
653+(<|) :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
654+(<|) = coparallel
644655
645656------------------------------------------------------------------------------
646657-- Monad
@@ -661,35 +672,35 @@ parbind par m f = go m
661672 yield a (Just r) = run $ f a `par` go r
662673 in g Nothing stp yield
663674
664−instance MonadAsync m => Monad (AParallelT m) where
675+instance MonadParallel m => Monad (CoparallelT m) where
665676 return = pure
666− (AParallelT m) >>= f = AParallelT $ parbind par m g
667− where g x = getAParallelT (f x)
677+ (CoparallelT m) >>= f = CoparallelT $ parbind par m g
678+ where g x = getCoparallelT (f x)
668679 par = S.joinStreamVar2 (SVarStyle Conjunction LIFO)
669680
670681------------------------------------------------------------------------------
671682-- Applicative
672683------------------------------------------------------------------------------
673684
674−instance MonadAsync m => Applicative (AParallelT m) where
675− pure a = AParallelT $ S.cons a Nothing
685+instance MonadParallel m => Applicative (CoparallelT m) where
686+ pure a = CoparallelT $ S.cons a Nothing
676687 (<*>) = ap
677688
678689------------------------------------------------------------------------------
679690-- Functor
680691------------------------------------------------------------------------------
681692
682−instance Monad m => Functor (AParallelT m) where
683− fmap f (AParallelT (Stream m)) = AParallelT $ Stream $ \_ stp yld ->
693+instance Monad m => Functor (CoparallelT m) where
694+ fmap f (CoparallelT (Stream m)) = CoparallelT $ Stream $ \_ stp yld ->
684695 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))))
686697 in m Nothing stp yield
687698
688699------------------------------------------------------------------------------
689700-- Num
690701------------------------------------------------------------------------------
691702
692−instance (MonadAsync m, Num a) => Num (AParallelT m a) where
703+instance (MonadParallel m, Num a) => Num (CoparallelT m a) where
693704 fromInteger n = pure (fromInteger n)
694705
695706 negate = fmap negate
@@ -700,14 +711,14 @@ instance (MonadAsync m, Num a) => Num (AParallelT m a) where
700711 (*) = liftA2 (*)
701712 (-) = liftA2 (-)
702713
703−instance (MonadAsync m, Fractional a) => Fractional (AParallelT m a) where
714+instance (MonadParallel m, Fractional a) => Fractional (CoparallelT m a) where
704715 fromRational n = pure (fromRational n)
705716
706717 recip = fmap recip
707718
708719 (/) = liftA2 (/)
709720
710−instance (MonadAsync m, Floating a) => Floating (AParallelT m a) where
721+instance (MonadParallel m, Floating a) => Floating (CoparallelT m a) where
711722 pi = pure pi
712723
713724 exp = fmap exp
@@ -764,7 +775,7 @@ instance (MonadAsync m, Floating a) => Floating (AParallelT m a) where
764775-- ThreadId 38: Delay 3
765776-- @
766777--
767−-- Unlike 'AParallelT' all iterations are guaranteed to run fairly
778+-- Unlike 'CoparallelT' all iterations are guaranteed to run fairly
768779-- concurrently, unconditionally.
769780--
770781-- 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
773784newtype ParallelT m a = ParallelT {getParallelT :: Stream m a}
774785 deriving (MonadTrans)
775786
776−deriving instance MonadAsync m => Monoid (ParallelT m a)
777−deriving instance MonadAsync m => Alternative (ParallelT m)
778−deriving instance MonadAsync m => MonadPlus (ParallelT m)
779−deriving instance MonadAsync m => MonadIO (ParallelT m)
780−deriving instance MonadAsync m => MonadThrow (ParallelT m)
781−deriving instance (MonadBase b m, MonadAsync m) => MonadBase b (ParallelT m)
782−deriving instance (MonadError e m, MonadAsync m) => MonadError e (ParallelT m)
783−deriving instance (MonadReader r m, MonadAsync m) => MonadReader r (ParallelT m)
784−deriving instance (MonadState s m, MonadAsync m) => MonadState s (ParallelT m)
787+deriving instance MonadParallel m => Monoid (ParallelT m a)
788+deriving instance MonadParallel m => Alternative (ParallelT m)
789+deriving instance MonadParallel m => MonadPlus (ParallelT m)
790+deriving instance MonadParallel m => MonadIO (ParallelT m)
791+deriving instance MonadParallel m => MonadThrow (ParallelT m)
792+deriving instance (MonadBase b m, MonadParallel m) => MonadBase b (ParallelT m)
793+deriving instance (MonadError e m, MonadParallel m) => MonadError e (ParallelT m)
794+deriving instance (MonadReader r m, MonadParallel m) => MonadReader r (ParallelT m)
795+deriving instance (MonadState s m, MonadParallel m) => MonadState s (ParallelT m)
785796
786797instance IsStream ParallelT where
787798 toStream = getParallelT
@@ -794,17 +805,17 @@ instance IsStream ParallelT where
794805-- | Polymorphic version of the 'Semigroup' operation '<>' of 'ParallelT'.
795806-- Merges two streams concurrently choosing elements from both fairly.
796807{-# 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
798809parallel m1 m2 = fromStream $ S.parallel (toStream m1) (toStream m2)
799810
800−instance MonadAsync m => Semigroup (ParallelT m a) where
811+instance MonadParallel m => Semigroup (ParallelT m a) where
801812 (<>) = parallel
802813
803814------------------------------------------------------------------------------
804815-- Monad
805816------------------------------------------------------------------------------
806817
807−instance MonadAsync m => Monad (ParallelT m) where
818+instance MonadParallel m => Monad (ParallelT m) where
808819 return = pure
809820 (ParallelT m) >>= f = ParallelT $ parbind par m g
810821 where g x = getParallelT (f x)
@@ -814,7 +825,7 @@ instance MonadAsync m => Monad (ParallelT m) where
814825-- Applicative
815826------------------------------------------------------------------------------
816827
817−instance MonadAsync m => Applicative (ParallelT m) where
828+instance MonadParallel m => Applicative (ParallelT m) where
818829 pure a = ParallelT $ S.cons a Nothing
819830 (<*>) = ap
820831
@@ -833,7 +844,7 @@ instance Monad m => Functor (ParallelT m) where
833844-- Num
834845------------------------------------------------------------------------------
835846
836−instance (MonadAsync m, Num a) => Num (ParallelT m a) where
847+instance (MonadParallel m, Num a) => Num (ParallelT m a) where
837848 fromInteger n = pure (fromInteger n)
838849
839850 negate = fmap negate
@@ -844,14 +855,14 @@ instance (MonadAsync m, Num a) => Num (ParallelT m a) where
844855 (*) = liftA2 (*)
845856 (-) = liftA2 (-)
846857
847−instance (MonadAsync m, Fractional a) => Fractional (ParallelT m a) where
858+instance (MonadParallel m, Fractional a) => Fractional (ParallelT m a) where
848859 fromRational n = pure (fromRational n)
849860
850861 recip = fmap recip
851862
852863 (/) = liftA2 (/)
853864
854−instance (MonadAsync m, Floating a) => Floating (ParallelT m a) where
865+instance (MonadParallel m, Floating a) => Floating (ParallelT m a) where
855866 pi = pure pi
856867
857868 exp = fmap exp
@@ -892,11 +903,10 @@ zipWith f m1 m2 = fromStream $ go (toStream m1) (toStream m2)
892903
893904-- | The applicative instance of 'ZipSerial' zips a number of streams serially
894905-- 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
896−-- in the following example instead of using a 'ZipSerial' type annotation.
906+-- those elements.
897907--
898908-- @
899−-- main = (toList . 'zipping' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
909+-- main = (toList . 'zipSerially' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
900910-- where s1 = fromFoldable [1, 2]
901911-- s2 = fromFoldable [3, 4]
902912-- s3 = fromFoldable [5, 6]
@@ -915,7 +925,7 @@ newtype ZipSerial m a = ZipSerial {getZipSerial :: Stream m a}
915925-- | Same as ZipSerial.
916926type ZipStream = ZipSerial
917927
918−deriving instance MonadAsync m => Alternative (ZipSerial m)
928+deriving instance MonadParallel m => Alternative (ZipSerial m)
919929
920930instance Monad m => Functor (ZipSerial m) where
921931 fmap f (ZipSerial (Stream m)) = ZipSerial $ Stream $ \_ stp yld ->
@@ -976,20 +986,25 @@ instance (Monad m, Floating a) => Floating (ZipSerial m a) where
976986-- Parallely Zipping Streams
977987------------------------------------------------------------------------------
978988
979−-- | Zip two streams asyncly (i.e. both the elements being zipped are generated
980−-- concurrently) using a pure zipping function.
981−zipAsyncWith :: (IsStream t, MonadAsync m)
989+-- | Zip two streams concurrently (i.e. both the elements being zipped are
990+-- generated concurrently) using a pure zipping function.
991+zipParallelWith :: (IsStream t, MonadParallel m)
982992 => (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
984994 ma <- async m1
985995 mb <- async m2
986996 (S.runStream (toStream (zipWith f ma mb))) Nothing stp yld
987997
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+
9881003-- | Like 'ZipSerial' but zips in parallel, it generates all the elements to
9891004-- be zipped concurrently.
9901005--
9911006-- @
992−-- main = (toList . 'zippingAsync' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
1007+-- main = (toList . 'zipParallely' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
9931008-- where s1 = fromFoldable [1, 2]
9941009-- s2 = fromFoldable [3, 4]
9951010-- s3 = fromFoldable [5, 6]
@@ -1001,27 +1016,30 @@ zipAsyncWith f m1 m2 = fromStream $ Stream $ \_ stp yld -> do
10011016-- The 'Semigroup' instance of this type works the same way as that of
10021017-- 'SerialT'.
10031018--
1004−newtype ZipAsync m a = ZipAsync {getZipAsync :: Stream m a}
1019+newtype ZipParallel m a = ZipParallel {getZipParallel :: Stream m a}
10051020 deriving (Semigroup, Monoid)
10061021
1007−deriving instance MonadAsync m => Alternative (ZipAsync m)
1022+{-# DEPRECATED ZipAsync "Please use ZipParallel instead." #-}
1023+type ZipAsync = ZipParallel
1024+
1025+deriving instance MonadParallel m => Alternative (ZipParallel m)
10081026
1009−instance Monad m => Functor (ZipAsync m) where
1010− fmap f (ZipAsync (Stream m)) = ZipAsync $ Stream $ \_ stp yld ->
1027+instance Monad m => Functor (ZipParallel m) where
1028+ fmap f (ZipParallel (Stream m)) = ZipParallel $ Stream $ \_ stp yld ->
10111029 let yield a Nothing = yld (f a) Nothing
10121030 yield a (Just r) = yld (f a)
1013− (Just (getZipAsync (fmap f (ZipAsync r))))
1031+ (Just (getZipParallel (fmap f (ZipParallel r))))
10141032 in m Nothing stp yield
10151033
1016−instance MonadAsync m => Applicative (ZipAsync m) where
1017− pure = ZipAsync . S.repeat
1018− (<*>) = zipAsyncWith id
1034+instance MonadParallel m => Applicative (ZipParallel m) where
1035+ pure = ZipParallel . S.repeat
1036+ (<*>) = zipParallelWith id
10191037
1020−instance IsStream ZipAsync where
1021− toStream = getZipAsync
1022− fromStream = ZipAsync
1038+instance IsStream ZipParallel where
1039+ toStream = getZipParallel
1040+ fromStream = ZipParallel
10231041
1024−instance (MonadAsync m, Num a) => Num (ZipAsync m a) where
1042+instance (MonadParallel m, Num a) => Num (ZipParallel m a) where
10251043 fromInteger n = pure (fromInteger n)
10261044
10271045 negate = fmap negate
@@ -1032,14 +1050,14 @@ instance (MonadAsync m, Num a) => Num (ZipAsync m a) where
10321050 (*) = liftA2 (*)
10331051 (-) = liftA2 (-)
10341052
1035−instance (MonadAsync m, Fractional a) => Fractional (ZipAsync m a) where
1053+instance (MonadParallel m, Fractional a) => Fractional (ZipParallel m a) where
10361054 fromRational n = pure (fromRational n)
10371055
10381056 recip = fmap recip
10391057
10401058 (/) = liftA2 (/)
10411059
1042−instance (MonadAsync m, Floating a) => Floating (ZipAsync m a) where
1060+instance (MonadParallel m, Floating a) => Floating (ZipParallel m a) where
10431061 pi = pure pi
10441062
10451063 exp = fmap exp
@@ -1073,30 +1091,45 @@ adapt = fromStream . toStream
10731091serially :: IsStream t => SerialT m a -> t m a
10741092serially = adapt
10751093
1076−-- | Fix the type of a polymorphic stream as 'InterleavedT'.
1077−interleaving :: IsStream t => InterleavedT m a -> t m a
1078−interleaving = adapt
1094+-- | Fix the type of a polymorphic stream as 'CoserialT'.
1095+coserially :: IsStream t => CoserialT m a -> t m a
1096+coserially = adapt
10791097
1080−-- | Fix the type of a polymorphic stream as 'AParallelT'.
1081−aparallely :: IsStream t => AParallelT m a -> t m a
1082−aparallely = adapt
1098+-- | Same as 'coserially'.
1099+{-# DEPRECATED interleaving "Please use coserially instead." #-}
1100+interleaving :: IsStream t => CoserialT m a -> t m a
1101+interleaving = coserially
10831102
1084−-- | Same as 'aparallely'.
1085−{-# DEPRECATED asyncly "Please use aparallely instead." #-}
1086−asyncly :: IsStream t => AParallelT m a -> t m a
1087−asyncly = 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'.
1108+{-# DEPRECATED asyncly "Please use coparallely instead." #-}
1109+asyncly :: IsStream t => CoparallelT m a -> t m a
1110+asyncly = coparallely
10881111
10891112-- | Fix the type of a polymorphic stream as 'ParallelT'.
10901113parallely :: IsStream t => ParallelT m a -> t m a
10911114parallely = adapt
10921115
10931116-- | 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." #-}
10941122zipping :: IsStream t => ZipSerial m a -> t m a
1095−zipping = adapt
1123+zipping = zipSerially
10961124
1097−-- | Fix the type of a polymorphic stream as 'ZipAsync'.
1098−zippingAsync :: IsStream t => ZipAsync m a -> t m a
1099−zippingAsync = adapt
1125+-- | Fix the type of a polymorphic stream as 'ZipParallel'.
1126+zipParallely :: IsStream t => ZipParallel m a -> t m a
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
11001133
11011134-------------------------------------------------------------------------------
11021135-- Running Streams, convenience functions specialized to types
@@ -1107,15 +1140,15 @@ zippingAsync = adapt
11071140runStreamT :: Monad m => SerialT m a -> m ()
11081141runStreamT = runStream
11091142
1110−-- | Same as @runStream . interleaving@.
1143+-- | Same as @runStream . coserially@.
11111144{-# DEPRECATED runInterleavedT "Please use 'runStream . interleaving' instead." #-}
11121145runInterleavedT :: Monad m => InterleavedT m a -> m ()
1113−runInterleavedT = runStream . interleaving
1146+runInterleavedT = runStream . coserially
11141147
1115−-- | Same as @runStream . aparallely@.
1116−{-# DEPRECATED runAsyncT "Please use 'runStream . aparallely' instead." #-}
1117−runAsyncT :: Monad m => AParallelT m a -> m ()
1118−runAsyncT = runStream . aparallely
1148+-- | Same as @runStream . coparallely@.
1149+{-# DEPRECATED runAsyncT "Please use 'runStream . coparallely' instead." #-}
1150+runAsyncT :: Monad m => CoparallelT m a -> m ()
1151+runAsyncT = runStream . coparallely
11191152
11201153-- | Same as @runStream . parallely@.
11211154{-# DEPRECATED runParallelT "Please use 'runStream . parallely' instead." #-}
@@ -1123,38 +1156,33 @@ runParallelT :: Monad m => ParallelT m a -> m ()
11231156runParallelT = runStream . parallely
11241157
11251158-- | Same as @runStream . zipping@.
1126−{-# DEPRECATED runZipStream "Please use 'runStream . zipping instead." #-}
1159+{-# DEPRECATED runZipStream "Please use 'runStream . zipSerially instead." #-}
11271160runZipStream :: Monad m => ZipSerial m a -> m ()
1128−runZipStream = runStream . zipping
1161+runZipStream = runStream . zipSerially
11291162
11301163-- | Same as @runStream . zippingAsync@.
1131−{-# DEPRECATED runZipAsync "Please use 'runStream . zippingAsync instead." #-}
1132−runZipAsync :: Monad m => ZipAsync m a -> m ()
1133−runZipAsync = runStream . zippingAsync
1164+{-# DEPRECATED runZipAsync "Please use 'runStream . zipParallely instead." #-}
1165+runZipAsync :: Monad m => ZipParallel m a -> m ()
1166+runZipAsync = runStream . zipParallely
11341167
11351168------------------------------------------------------------------------------
11361169-- Fold Utilities
11371170------------------------------------------------------------------------------
11381171
1139−-- $foldutils
1140−-- These utilities are designed to pass the first argument as one of the sum
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.
1172+-- | A variant of 'Data.Foldable.fold' that allows you to fold a 'Foldable'
1173+-- container of streams using the specified stream sum operation.
11461174--
1147−-- @foldWith (<>) $ map return [1..3]@
1175+-- @foldWith 'parallel' $ map return [1..3]@
11481176{-# INLINABLE foldWith #-}
11491177foldWith :: (IsStream t, Foldable f)
11501178 => (t m a -> t m a -> t m a) -> f (t m a) -> t m a
11511179foldWith f = foldr f nil
11521180
1153−-- | Like 'foldMap' but allows you to specify a binary sum style composition
1154−-- operator to fold a container of streams. Maps a monadic streaming action on
1155−-- the container before folding it.
1181+-- | A variant of 'foldMap' that allows you to map a monadic streaming action
1182+-- on a 'Foldable' container and then fold it using the specified stream sum
1183+-- operation.
11561184--
1157−-- @foldMapWith (<>) return [1..3]@
1185+-- @foldMapWith 'parallel' return [1..3]@
11581186{-# INLINABLE foldMapWith #-}
11591187foldMapWith :: (IsStream t, Foldable f)
11601188 => (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
1919toListSerial :: SerialT IO a -> IO [a]
2020toListSerial = A.toList . serially
2121
22−toListInterleaved :: InterleavedT IO a -> IO [a]
23−toListInterleaved = A.toList . interleaving
22+toListInterleaved :: CoserialT IO a -> IO [a]
23+toListInterleaved = A.toList . coserially
2424
25−toListAsync :: AParallelT IO a -> IO [a]
26−toListAsync = A.toList . aparallely
25+toListAsync :: CoparallelT IO a -> IO [a]
26+toListAsync = A.toList . coparallely
2727
2828toListParallel :: ParallelT IO a -> IO [a]
2929toListParallel = A.toList . parallely
@@ -88,19 +88,19 @@ main = hspec $ do
8888 ---------------------------------------------------------------------------
8989
9090 describe "Serial Composition" $ compose serially mempty id
91− describe "Interleaved Composition" $ compose interleaving mempty sort
92− describe "Left biased parallel Composition" $ compose aparallely mempty sort
91+ describe "Interleaved Composition" $ compose coserially mempty sort
92+ describe "Left biased parallel Composition" $ compose coparallely mempty sort
9393 describe "Fair parallel Composition" $ compose parallely mempty sort
94− describe "Semigroup Composition for ZipSerial" $ compose zipping mempty id
95− describe "Semigroup Composition for ZipAsync" $ compose zippingAsync mempty id
94+ describe "Semigroup Composition for ZipSerial" $ compose zipSerially mempty id
95+ describe "Semigroup Composition for ZipAsync" $ compose zipParallely mempty id
9696 -- XXX need to check alternative compositions as well
9797 ---------------------------------------------------------------------------
9898 -- Monoidal Composition ordering checks
9999 ---------------------------------------------------------------------------
100100
101− describe "Serial interleaved ordering check" $ interleaveCheck interleaving
101+ describe "Serial interleaved ordering check" $ interleaveCheck coserially
102102 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
104104 describe "Fair parallel time order check" $ parallelCheck parallely
105105
106106 ---------------------------------------------------------------------------
@@ -112,7 +112,7 @@ main = hspec $ do
112112
113113 describe "<> and <=>" $ composeAndComposeSimple
114114 serially
115− interleaving
115+ coserially
116116 ([ [1 .. 9]
117117 , [1 .. 9]
118118 , [1, 3, 2, 4, 6, 5, 7, 9, 8]
@@ -120,8 +120,8 @@ main = hspec $ do
120120 ])
121121
122122 describe "<=> and <=>" $ composeAndComposeSimple
123− interleaving
124− interleaving
123+ coserially
124+ coserially
125125 ([ [1, 4, 2, 7, 3, 5, 8, 6, 9]
126126 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
127127 , [1, 4, 3, 7, 2, 6, 9, 5, 8]
@@ -129,7 +129,7 @@ main = hspec $ do
129129 ])
130130
131131 describe "<=> and <>" $ composeAndComposeSimple
132− interleaving
132+ coserially
133133 serially
134134 ([ [1, 4, 2, 7, 3, 5, 8, 6, 9]
135135 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
@@ -183,7 +183,7 @@ main = hspec $ do
183183 ---------------------------------------------------------------------------
184184
185185 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
187187 describe "Fair parallel loops (<|>)" $ loops parallely sort sort
188188
189189 ---------------------------------------------------------------------------
@@ -191,23 +191,23 @@ main = hspec $ do
191191 ---------------------------------------------------------------------------
192192
193193 describe "Bind and compose1" $ bindAndComposeSimple serially serially
194− describe "Bind and compose2" $ bindAndComposeSimple serially interleaving
195− describe "Bind and compose3" $ bindAndComposeSimple serially aparallely
194+ describe "Bind and compose2" $ bindAndComposeSimple serially coserially
195+ describe "Bind and compose3" $ bindAndComposeSimple serially coparallely
196196 describe "Bind and compose4" $ bindAndComposeSimple serially parallely
197197
198− describe "Bind and compose1" $ bindAndComposeSimple interleaving serially
199− describe "Bind and compose2" $ bindAndComposeSimple interleaving interleaving
200− describe "Bind and compose3" $ bindAndComposeSimple interleaving aparallely
201− describe "Bind and compose4" $ bindAndComposeSimple interleaving parallely
198+ describe "Bind and compose1" $ bindAndComposeSimple coserially serially
199+ describe "Bind and compose2" $ bindAndComposeSimple coserially coserially
200+ describe "Bind and compose3" $ bindAndComposeSimple coserially coparallely
201+ describe "Bind and compose4" $ bindAndComposeSimple coserially parallely
202202
203− describe "Bind and compose1" $ bindAndComposeSimple aparallely serially
204− describe "Bind and compose2" $ bindAndComposeSimple aparallely interleaving
205− describe "Bind and compose3" $ bindAndComposeSimple aparallely aparallely
206− describe "Bind and compose4" $ bindAndComposeSimple aparallely parallely
203+ describe "Bind and compose1" $ bindAndComposeSimple coparallely serially
204+ describe "Bind and compose2" $ bindAndComposeSimple coparallely coserially
205+ describe "Bind and compose3" $ bindAndComposeSimple coparallely coparallely
206+ describe "Bind and compose4" $ bindAndComposeSimple coparallely parallely
207207
208208 describe "Bind and compose1" $ bindAndComposeSimple parallely serially
209− describe "Bind and compose2" $ bindAndComposeSimple parallely interleaving
210− describe "Bind and compose3" $ bindAndComposeSimple parallely aparallely
209+ describe "Bind and compose2" $ bindAndComposeSimple parallely coserially
210+ describe "Bind and compose3" $ bindAndComposeSimple parallely coparallely
211211 describe "Bind and compose4" $ bindAndComposeSimple parallely parallely
212212
213213 let fldr, fldl :: (IsStream t, Semigroup (t IO Int)) => [t IO Int] -> t IO Int
@@ -217,36 +217,36 @@ main = hspec $ do
217217 forM_ [fldr, fldl] $ \k ->
218218 describe "Bind and compose" $ bindAndComposeHierarchy serially serially k
219219 forM_ [fldr, fldl] $ \k ->
220− describe "Bind and compose" $ bindAndComposeHierarchy serially interleaving k
220+ describe "Bind and compose" $ bindAndComposeHierarchy serially coserially k
221221 forM_ [fldr, fldl] $ \k ->
222− describe "Bind and compose" $ bindAndComposeHierarchy serially aparallely k
222+ describe "Bind and compose" $ bindAndComposeHierarchy serially coparallely k
223223 forM_ [fldr, fldl] $ \k ->
224224 describe "Bind and compose" $ bindAndComposeHierarchy serially parallely k
225225
226226 forM_ [fldr, fldl] $ \k ->
227− describe "Bind and compose" $ bindAndComposeHierarchy interleaving serially k
227+ describe "Bind and compose" $ bindAndComposeHierarchy coserially serially k
228228 forM_ [fldr, fldl] $ \k ->
229− describe "Bind and compose" $ bindAndComposeHierarchy interleaving interleaving k
229+ describe "Bind and compose" $ bindAndComposeHierarchy coserially coserially k
230230 forM_ [fldr, fldl] $ \k ->
231− describe "Bind and compose" $ bindAndComposeHierarchy interleaving aparallely k
231+ describe "Bind and compose" $ bindAndComposeHierarchy coserially coparallely k
232232 forM_ [fldr, fldl] $ \k ->
233− describe "Bind and compose" $ bindAndComposeHierarchy interleaving parallely k
233+ describe "Bind and compose" $ bindAndComposeHierarchy coserially parallely k
234234
235235 forM_ [fldr, fldl] $ \k ->
236− describe "Bind and compose" $ bindAndComposeHierarchy aparallely serially k
236+ describe "Bind and compose" $ bindAndComposeHierarchy coparallely serially k
237237 forM_ [fldr, fldl] $ \k ->
238− describe "Bind and compose" $ bindAndComposeHierarchy aparallely interleaving k
238+ describe "Bind and compose" $ bindAndComposeHierarchy coparallely coserially k
239239 forM_ [fldr, fldl] $ \k ->
240− describe "Bind and compose" $ bindAndComposeHierarchy aparallely aparallely k
240+ describe "Bind and compose" $ bindAndComposeHierarchy coparallely coparallely k
241241 forM_ [fldr, fldl] $ \k ->
242− describe "Bind and compose" $ bindAndComposeHierarchy aparallely parallely k
242+ describe "Bind and compose" $ bindAndComposeHierarchy coparallely parallely k
243243
244244 forM_ [fldr, fldl] $ \k ->
245245 describe "Bind and compose" $ bindAndComposeHierarchy parallely serially k
246246 forM_ [fldr, fldl] $ \k ->
247− describe "Bind and compose" $ bindAndComposeHierarchy parallely interleaving k
247+ describe "Bind and compose" $ bindAndComposeHierarchy parallely coserially k
248248 forM_ [fldr, fldl] $ \k ->
249− describe "Bind and compose" $ bindAndComposeHierarchy parallely aparallely k
249+ describe "Bind and compose" $ bindAndComposeHierarchy parallely coparallely k
250250 forM_ [fldr, fldl] $ \k ->
251251 describe "Bind and compose" $ bindAndComposeHierarchy parallely parallely k
252252
@@ -553,11 +553,11 @@ mixedOps = do
553553 x1 <- parallely $ return 1 <> return 2
554554 liftIO $ return ()
555555 liftIO $ putStr ""
556− y1 <- aparallely $ return 1 <> return 2
556+ y1 <- coparallely $ return 1 <> return 2
557557 z1 <- do
558558 x11 <- return 1 <> return 2
559− y11 <- aparallely $ return 1 <> return 2
560− z11 <- interleaving $ return 1 <> return 2
559+ y11 <- coparallely $ return 1 <> return 2
560+ z11 <- coserially $ return 1 <> return 2
561561 liftIO $ return ()
562562 liftIO $ putStr ""
563563 return (x11 + y11 + z11)
test/Prop.hs+59−59
@@ -260,7 +260,7 @@ zipMonadic constr t eq (a, b) =
260260 stream2 <-
261261 run
262262 ((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)))
264264 let list = getZipList $ (,) <$> ZipList a <*> ZipList b
265265 equals eq stream1 list
266266 equals eq stream2 list
@@ -316,24 +316,24 @@ main = hspec $ do
316316 describe "Functor operations" $ do
317317 functorOps A.fromFoldable "serially" serially (==)
318318 functorOps folded "serially folded" serially (==)
319− functorOps A.fromFoldable "interleaving" interleaving (==)
320− functorOps folded "interleaving folded" interleaving (==)
321− functorOps A.fromFoldable "aparallely" aparallely sortEq
322− functorOps folded "aparallely folded" aparallely sortEq
319+ functorOps A.fromFoldable "coserially" coserially (==)
320+ functorOps folded "coserially folded" coserially (==)
321+ functorOps A.fromFoldable "coparallely" coparallely sortEq
322+ functorOps folded "coparallely folded" coparallely sortEq
323323 functorOps A.fromFoldable "parallely" parallely sortEq
324324 functorOps folded "parallely folded" parallely sortEq
325− functorOps A.fromFoldable "zipping" zipping (==)
326− functorOps folded "zipping folded" zipping (==)
327− functorOps A.fromFoldable "zippingAsync" zippingAsync (==)
328− functorOps folded "zippingAsync folded" zippingAsync (==)
325+ functorOps A.fromFoldable "zipSerially" zipSerially (==)
326+ functorOps folded "zipSerially folded" zipSerially (==)
327+ functorOps A.fromFoldable "zipParallely" zipParallely (==)
328+ functorOps folded "zipParallely folded" zipParallely (==)
329329
330330 describe "Semigroup operations" $ do
331331 semigroupOps "serially" serially (==)
332− semigroupOps "interleaving" interleaving (==)
333− semigroupOps "aparallely" aparallely sortEq
332+ semigroupOps "coserially" coserially (==)
333+ semigroupOps "coparallely" coparallely sortEq
334334 semigroupOps "parallely" parallely sortEq
335− semigroupOps "zipping" zipping (==)
336− semigroupOps "zippingAsync" zippingAsync (==)
335+ semigroupOps "zipSerially" zipSerially (==)
336+ semigroupOps "zipParallely" zipParallely (==)
337337
338338 describe "Applicative operations" $ do
339339 -- The tests using sorted equality are weaker tests
@@ -341,92 +341,92 @@ main = hspec $ do
341341 -- XXX applicative with three arguments
342342 prop "serially applicative" $ applicativeOps A.fromFoldable serially (==)
343343 prop "serially applicative folded" $ applicativeOps folded serially (==)
344− prop "interleaving applicative" $ applicativeOps A.fromFoldable interleaving sortEq
345− prop "interleaving applicative folded" $ applicativeOps folded interleaving sortEq
346− prop "aparallely applicative" $ applicativeOps A.fromFoldable aparallely sortEq
347− prop "aparallely applicative folded" $ applicativeOps folded aparallely sortEq
344+ prop "coserially applicative" $ applicativeOps A.fromFoldable coserially sortEq
345+ prop "coserially applicative folded" $ applicativeOps folded coserially sortEq
346+ prop "coparallely applicative" $ applicativeOps A.fromFoldable coparallely sortEq
347+ prop "coparallely applicative folded" $ applicativeOps folded coparallely sortEq
348348 prop "parallely applicative folded" $ applicativeOps folded parallely sortEq
349349
350350 describe "Zip operations" $ do
351− prop "zipping applicative" $ zipApplicative A.fromFoldable zipping (==)
351+ prop "zipSerially applicative" $ zipApplicative A.fromFoldable zipSerially (==)
352352 -- XXX this hangs
353− -- prop "zippingAsync applicative" $ zipApplicative zippingAsync (==)
353+ -- prop "zipParallely applicative" $ zipApplicative zipParallely (==)
354354 prop "zip monadic serially" $ zipMonadic A.fromFoldable serially (==)
355355 prop "zip monadic serially folded" $ zipMonadic folded serially (==)
356− prop "zip monadic interleaving" $ zipMonadic A.fromFoldable interleaving (==)
357− prop "zip monadic interleaving folded" $ zipMonadic folded interleaving (==)
358− prop "zip monadic aparallely" $ zipMonadic A.fromFoldable aparallely (==)
359− prop "zip monadic aparallely folded" $ zipMonadic folded aparallely (==)
356+ prop "zip monadic coserially" $ zipMonadic A.fromFoldable coserially (==)
357+ prop "zip monadic coserially folded" $ zipMonadic folded coserially (==)
358+ prop "zip monadic coparallely" $ zipMonadic A.fromFoldable coparallely (==)
359+ prop "zip monadic coparallely folded" $ zipMonadic folded coparallely (==)
360360 prop "zip monadic parallely" $ zipMonadic A.fromFoldable parallely (==)
361361 prop "zip monadic parallely folded" $ zipMonadic folded parallely (==)
362362
363363 describe "Monad operations" $ do
364364 prop "serially monad then" $ monadThen A.fromFoldable serially (==)
365− prop "interleaving monad then" $ monadThen A.fromFoldable interleaving sortEq
366− prop "aparallely monad then" $ monadThen A.fromFoldable aparallely sortEq
365+ prop "coserially monad then" $ monadThen A.fromFoldable coserially sortEq
366+ prop "coparallely monad then" $ monadThen A.fromFoldable coparallely sortEq
367367 prop "parallely monad then" $ monadThen A.fromFoldable parallely sortEq
368368
369369 prop "serially monad then folded" $ monadThen folded serially (==)
370− prop "interleaving monad then folded" $ monadThen folded interleaving sortEq
371− prop "aparallely monad then folded" $ monadThen folded aparallely sortEq
370+ prop "coserially monad then folded" $ monadThen folded coserially sortEq
371+ prop "coparallely monad then folded" $ monadThen folded coparallely sortEq
372372 prop "parallely monad then folded" $ monadThen folded parallely sortEq
373373
374374 prop "serially monad bind" $ monadBind A.fromFoldable serially (==)
375− prop "interleaving monad bind" $ monadBind A.fromFoldable interleaving sortEq
376− prop "aparallely monad bind" $ monadBind A.fromFoldable aparallely sortEq
375+ prop "coserially monad bind" $ monadBind A.fromFoldable coserially sortEq
376+ prop "coparallely monad bind" $ monadBind A.fromFoldable coparallely sortEq
377377 prop "parallely monad bind" $ monadBind A.fromFoldable parallely sortEq
378378
379379 describe "Stream transform operations" $ do
380380 transformOps A.fromFoldable "serially" serially (==)
381− transformOps A.fromFoldable "interleaving" interleaving (==)
382− transformOps A.fromFoldable "zipping" zipping (==)
383− transformOps A.fromFoldable "zippingAsync" zippingAsync (==)
384− transformOps A.fromFoldable "aparallely" aparallely sortEq
381+ transformOps A.fromFoldable "coserially" coserially (==)
382+ transformOps A.fromFoldable "zipSerially" zipSerially (==)
383+ transformOps A.fromFoldable "zipParallely" zipParallely (==)
384+ transformOps A.fromFoldable "coparallely" coparallely sortEq
385385 transformOps A.fromFoldable "parallely" parallely sortEq
386386
387387 transformOps folded "serially folded" serially (==)
388− transformOps folded "interleaving folded" interleaving (==)
389− transformOps folded "zipping folded" zipping (==)
390− transformOps folded "zippingAsync folded" zippingAsync (==)
391− transformOps folded "aparallely folded" aparallely sortEq
388+ transformOps folded "coserially folded" coserially (==)
389+ transformOps folded "zipSerially folded" zipSerially (==)
390+ transformOps folded "zipParallely folded" zipParallely (==)
391+ transformOps folded "coparallely folded" coparallely sortEq
392392 transformOps folded "parallely folded" parallely sortEq
393393
394394 transformOpsWord8 A.fromFoldable "serially" serially
395− transformOpsWord8 A.fromFoldable "interleaving" interleaving
396− transformOpsWord8 A.fromFoldable "zipping" zipping
397− transformOpsWord8 A.fromFoldable "zippingAsync" zippingAsync
398− transformOpsWord8 A.fromFoldable "aparallely" aparallely
395+ transformOpsWord8 A.fromFoldable "coserially" coserially
396+ transformOpsWord8 A.fromFoldable "zipSerially" zipSerially
397+ transformOpsWord8 A.fromFoldable "zipParallely" zipParallely
398+ transformOpsWord8 A.fromFoldable "coparallely" coparallely
399399 transformOpsWord8 A.fromFoldable "parallely" parallely
400400
401401 transformOpsWord8 folded "serially folded" serially
402− transformOpsWord8 folded "interleaving folded" interleaving
403− transformOpsWord8 folded "zipping folded" zipping
404− transformOpsWord8 folded "zippingAsync folded" zippingAsync
405− transformOpsWord8 folded "aparallely folded" aparallely
402+ transformOpsWord8 folded "coserially folded" coserially
403+ transformOpsWord8 folded "zipSerially folded" zipSerially
404+ transformOpsWord8 folded "zipParallely folded" zipParallely
405+ transformOpsWord8 folded "coparallely folded" coparallely
406406 transformOpsWord8 folded "parallely folded" parallely
407407
408408 describe "Stream elimination operations" $ do
409409 eliminationOps A.fromFoldable "serially" serially
410− eliminationOps A.fromFoldable "interleaving" interleaving
411− eliminationOps A.fromFoldable "zipping" zipping
412− eliminationOps A.fromFoldable "zippingAsync" zippingAsync
413− eliminationOps A.fromFoldable "aparallely" aparallely
410+ eliminationOps A.fromFoldable "coserially" coserially
411+ eliminationOps A.fromFoldable "zipSerially" zipSerially
412+ eliminationOps A.fromFoldable "zipParallely" zipParallely
413+ eliminationOps A.fromFoldable "coparallely" coparallely
414414 eliminationOps A.fromFoldable "parallely" parallely
415415
416416 eliminationOps folded "serially folded" serially
417− eliminationOps folded "interleaving folded" interleaving
418− eliminationOps folded "zipping folded" zipping
419− eliminationOps folded "zippingAsync folded" zippingAsync
420− eliminationOps folded "aparallely folded" aparallely
417+ eliminationOps folded "coserially folded" coserially
418+ eliminationOps folded "zipSerially folded" zipSerially
419+ eliminationOps folded "zipParallely folded" zipParallely
420+ eliminationOps folded "coparallely folded" coparallely
421421 eliminationOps folded "parallely folded" parallely
422422
423423 describe "Stream elimination operations" $ do
424424 serialEliminationOps A.fromFoldable "serially" serially
425− serialEliminationOps A.fromFoldable "interleaving" interleaving
426− serialEliminationOps A.fromFoldable "zipping" zipping
427− serialEliminationOps A.fromFoldable "zippingAsync" zippingAsync
425+ serialEliminationOps A.fromFoldable "coserially" coserially
426+ serialEliminationOps A.fromFoldable "zipSerially" zipSerially
427+ serialEliminationOps A.fromFoldable "zipParallely" zipParallely
428428
429429 serialEliminationOps folded "serially folded" serially
430− serialEliminationOps folded "interleaving folded" interleaving
431− serialEliminationOps folded "zipping folded" zipping
432− serialEliminationOps folded "zippingAsync folded" zippingAsync
430+ serialEliminationOps folded "coserially folded" coserially
431+ serialEliminationOps folded "zipSerially folded" zipSerially
432+ serialEliminationOps folded "zipParallely folded" zipParallely