on master help sign in
rename InterleavedT=>CoserialT, AParallelT=>CoparallelT
acd550cHarendra Kumar
Changelog.md+22−16
@@ -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,45 @@
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 * `StreamT` to `SerialT`
34− * `runStreamT` to `runSerialT`
35 * `ZipStream` to `ZipSerial`
35 * `ZipStream` to `ZipSerial`
36− * `runZipStream` to `runZipSerial`
37− * `AsyncT` to `AParallelT`
36+ * `AsyncT` to `CoparallelT`
38− * `runAsyncT` to `runAParallelT`
37+ * `interleaving` to `coserially`
39− * `asyncly` to `aparallely`
38+ * `asyncly` to `coparallely`
40 * `Streaming` to `IsStream`
39 * `Streaming` to `IsStream`
41 * `runStreaming` to `runStream`
40 * `runStreaming` to `runStream`
42− * `<=>` to `interleave`
41+ * `<=>` to `coserial`
43− * `<|` to `aparallel`
42+ * `<|` to `coparallel`
44 * `each` to `fromFoldable`
43 * `each` to `fromFoldable`
45 * `scan` to `scanx`
44 * `scan` to `scanx`
46 * `foldl` to `foldx`
45 * `foldl` to `foldx`
47 * `foldlM` to `foldxM`
46 * `foldlM` to `foldxM`
47+* Deprecate and remove the following symbols:
48+ * `runStreamT`
49+ * `runInterleavedT`
50+ * `runAsyncT`
51+ * `runParallelT`
52+ * `runZipStream`
53+ * `runZipAsync`
48
54
49### Enhancements
55### Enhancements
50* Add the following functions:
56* Add the following functions:
51 * `scanl'` strict left scan
57 * `scanl'` strict left scan
52 * `foldl'` strict left fold
58 * `foldl'` strict left fold
53 * `foldlM'` strict left fold with a monadic fold function
59 * `foldlM'` strict left fold with a monadic fold function
54− * `append` run two streams serially one after the other
60+ * `serial` run two streams serially one after the other
55 * `parallel` run two streams in parallel (replaces `<|>`)
61 * `parallel` run two streams in parallel (replaces `<|>`)
56
62
57## 0.1.2
63## 0.1.2
benchmark/Main.hs+2−2
@@ -141,13 +141,13 @@ 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
146streamly_interleaved = streamly_basic (A.toList . A.coserially)
146streamly_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
152streamly_async = streamly_basic (A.toList . A.coparallely)
152streamly_async = streamly_basic (A.toList . A.coparallely)
153
153
src/Streamly.hs+12−10
@@ -21,8 +21,8 @@ module Streamly
21 -- * General Stream Styles
21 -- * General Stream Styles
22 -- $product
22 -- $product
23 , SerialT
23 , SerialT
24− , InterleavedT
24+ , CoserialT
25− , AParallelT
25+ , CoparallelT
26 , ParallelT
26 , ParallelT
27
27
28 -- * Zip Style Streams
28 -- * Zip Style Streams
@@ -77,8 +77,10 @@ module Streamly
77 , runAsyncT
77 , runAsyncT
78 , runZipStream
78 , runZipStream
79 , StreamT
79 , StreamT
80+ , InterleavedT
80 , AsyncT
81 , AsyncT
81 , ZipStream
82 , ZipStream
83+ , interleaving
82 , asyncly
84 , asyncly
83 , (<=>)
85 , (<=>)
84 , (<|)
86 , (<|)
@@ -126,22 +128,22 @@ import Control.Monad.Trans.Class (MonadTrans (..))
126
128
127-- $overview
129-- $overview
128--
130--
129−-- Streamly provides six distinct stream types i.e. 'SerialT', 'InterleavedT',
131+-- Streamly provides six distinct stream types i.e. 'SerialT', 'CoserialT',
130−-- 'AParallelT' and 'ParallelT', 'ZipStream' and 'ZipAsync', each representing a
132+-- 'CoparallelT' and 'ParallelT', 'ZipStream' and 'ZipAsync', each representing a
131-- stream of elements. All these types have the same underlying representation
133-- stream of elements. All these types have the same underlying representation
132-- and can be adapted from one to another using type adaptor combinators
134-- 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
135-- 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
136-- which helps converting the specific type to and from the underlying generic
135-- stream type.
137-- stream type.
136--
138--
137−-- The types 'SerialT', 'InterleavedT', 'AParallelT' and 'ParallelT' are 'Monad'
139+-- The types 'SerialT', 'CoserialT', 'CoparallelT' and 'ParallelT' are 'Monad'
138-- transformers with the monadic bind operation combining streams in a product
140-- 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
141-- 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.
142-- 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
143-- 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
144-- terms of the ordering and time sequence in which the elements from two
143−-- streams are combined. 'SerialT' and 'InterleavedT' compose streams serially
145+-- streams are combined. 'SerialT' and 'CoserialT' compose streams serially
144−-- whereas 'AParallelT' and 'ParallelT' are their concurrent counterparts. See the
146+-- whereas 'CoparallelT' and 'ParallelT' are their concurrent counterparts. See the
145-- documentation of the respective types for more details.
147-- documentation of the respective types for more details.
146--
148--
147-- The types 'ZipStream' and 'ZipAsync' provide 'Applicative' instances to zip
149-- The types 'ZipStream' and 'ZipAsync' provide 'Applicative' instances to zip
@@ -156,7 +158,7 @@ import Control.Monad.Trans.Class (MonadTrans (..))
156-- (concurrent or serial) in which the elements in the resulting stream are
158-- (concurrent or serial) in which the elements in the resulting stream are
157-- produced depends on the type of the stream.
159-- produced depends on the type of the stream.
158--
160--
159−-- Concurrent composition types 'AParallelT', 'ParallelT', 'ZipAsync' require the
161+-- Concurrent composition types 'CoparallelT', 'ParallelT', 'ZipAsync' require the
160-- underlying monad of the streaming monad transformer to be 'MonadAsync'.
162-- underlying monad of the streaming monad transformer to be 'MonadAsync'.
161--
163--
162-- For more details please see the "Streamly.Tutorial" and "Streamly.Examples"
164-- For more details please see the "Streamly.Tutorial" and "Streamly.Examples"
@@ -168,8 +170,8 @@ import Control.Monad.Trans.Class (MonadTrans (..))
168-- $product
170-- $product
169--
171--
170-- Streams that compose serially or non-concurrently come in two flavors i.e.
172-- Streams that compose serially or non-concurrently come in two flavors i.e.
171−-- 'SerialT' and 'InterleavedT'. Both of these serial flavors have
173+-- 'SerialT' and 'CoserialT'. Both of these serial flavors have
172−-- corresponding concurrent equivalents, those are 'AParallelT' and 'ParallelT'
174+-- corresponding concurrent equivalents, those are 'CoparallelT' and 'ParallelT'
173-- respectively.
175-- respectively.
174
176
175-- $zipping
177-- $zipping
src/Streamly/Streams.hs+72−62
@@ -58,8 +58,9 @@ module Streamly.Streams
58 -- * Stream Styles
58 -- * Stream Styles
59 , SerialT
59 , SerialT
60 , StreamT -- deprecated
60 , StreamT -- deprecated
61+ , CoserialT
61− , InterleavedT
62+ , InterleavedT -- deprecated
62− , AParallelT
63+ , CoparallelT
63 , AsyncT -- deprecated
64 , AsyncT -- deprecated
64 , ParallelT
65 , ParallelT
65 , ZipSerial
66 , ZipSerial
@@ -69,6 +70,7 @@ module Streamly.Streams
69 -- * Type Adapters
70 -- * Type Adapters
70 , serially
71 , serially
71 , coserially
72 , coserially
73+ , interleaving -- deprecated
72 , coparallely
74 , coparallely
73 , asyncly -- deprecated
75 , asyncly -- deprecated
74 , parallely
76 , parallely
@@ -416,10 +418,10 @@ instance (Monad m, Floating a) => Floating (SerialT m a) where
416 logBase = liftA2 logBase
418 logBase = liftA2 logBase
417
419
418------------------------------------------------------------------------------
420------------------------------------------------------------------------------
419−-- InterleavedT
421+-- CoserialT
420------------------------------------------------------------------------------
422------------------------------------------------------------------------------
421
423
422−-- | The 'Semigroup' instance of 'InterleavedT' interleaves two streams,
424+-- | The 'Semigroup' instance of 'CoserialT' interleaves two streams,
423-- yielding one element from each stream alternately.
425-- yielding one element from each stream alternately.
424--
426--
425-- @
427-- @
@@ -449,31 +451,34 @@ instance (Monad m, Floating a) => Floating (SerialT m a) where
449-- Note that interleaving composition can only combine a finite number of
451-- Note that interleaving composition can only combine a finite number of
450-- streams as it needs to retain state for each unfinished stream.
452-- streams as it needs to retain state for each unfinished stream.
451--
453--
452−newtype InterleavedT m a = InterleavedT {getInterleavedT :: Stream m a}
454+newtype CoserialT m a = CoserialT {getCoserialT :: Stream m a}
453 deriving (Monoid, MonadTrans, MonadIO, MonadThrow)
455 deriving (Monoid, MonadTrans, MonadIO, MonadThrow)
454
456
455−deriving instance MonadAsync m => Alternative (InterleavedT m)
457+deriving instance MonadAsync m => Alternative (CoserialT m)
456−deriving instance MonadAsync m => MonadPlus (InterleavedT m)
458+deriving instance MonadAsync m => MonadPlus (CoserialT m)
457−deriving instance (MonadBase b m, Monad m) => MonadBase b (InterleavedT m)
459+deriving instance (MonadBase b m, Monad m) => MonadBase b (CoserialT m)
458−deriving instance MonadError e m => MonadError e (InterleavedT m)
460+deriving instance MonadError e m => MonadError e (CoserialT m)
459−deriving instance MonadReader r m => MonadReader r (InterleavedT m)
461+deriving instance MonadReader r m => MonadReader r (CoserialT m)
460−deriving instance MonadState s m => MonadState s (InterleavedT m)
462+deriving instance MonadState s m => MonadState s (CoserialT m)
461
463
464+{-# DEPRECATED InterleavedT "Please use 'CoserialT' instead." #-}
465+type InterleavedT = CoserialT
466+
462−instance IsStream InterleavedT where
467+instance IsStream CoserialT where
463− toStream = getInterleavedT
468+ toStream = getCoserialT
464− fromStream = InterleavedT
469+ fromStream = CoserialT
465
470
466------------------------------------------------------------------------------
471------------------------------------------------------------------------------
467-- Semigroup
472-- Semigroup
468------------------------------------------------------------------------------
473------------------------------------------------------------------------------
469
474
470−-- | Polymorphic version of the 'Semigroup' operation '<>' of 'InterleavedT'.
475+-- | Polymorphic version of the 'Semigroup' operation '<>' of 'CoserialT'.
471-- Interleaves two streams, yielding one element from each stream alternately.
476-- Interleaves two streams, yielding one element from each stream alternately.
472{-# INLINE coserial #-}
477{-# INLINE coserial #-}
473coserial :: IsStream t => t m a -> t m a -> t m a
478coserial :: IsStream t => t m a -> t m a -> t m a
474coserial m1 m2 = fromStream $ S.coserial (toStream m1) (toStream m2)
479coserial m1 m2 = fromStream $ S.coserial (toStream m1) (toStream m2)
475
480
476−instance Semigroup (InterleavedT m a) where
481+instance Semigroup (CoserialT m a) where
477 (<>) = coserial
482 (<>) = coserial
478
483
479infixr 5 <=>
484infixr 5 <=>
@@ -488,9 +493,9 @@ infixr 5 <=>
488-- Monad
493-- Monad
489------------------------------------------------------------------------------
494------------------------------------------------------------------------------
490
495
491−instance Monad m => Monad (InterleavedT m) where
496+instance Monad m => Monad (CoserialT m) where
492 return = pure
497 return = pure
493− (InterleavedT (Stream m)) >>= f = InterleavedT $ Stream $ \_ stp yld ->
498+ (CoserialT (Stream m)) >>= f = CoserialT $ Stream $ \_ stp yld ->
494 let run x = (S.runStream x) Nothing stp yld
499 let run x = (S.runStream x) Nothing stp yld
495 yield a Nothing = run $ toStream (f a)
500 yield a Nothing = run $ toStream (f a)
496 yield a (Just r) = run $ toStream $ f a <> (fromStream r >>= f)
501 yield a (Just r) = run $ toStream $ f a <> (fromStream r >>= f)
@@ -500,26 +505,26 @@ instance Monad m => Monad (InterleavedT m) where
500-- Applicative
505-- Applicative
501------------------------------------------------------------------------------
506------------------------------------------------------------------------------
502
507
503−instance Monad m => Applicative (InterleavedT m) where
508+instance Monad m => Applicative (CoserialT m) where
504− pure a = InterleavedT $ S.cons a Nothing
509+ pure a = CoserialT $ S.cons a Nothing
505 (<*>) = ap
510 (<*>) = ap
506
511
507------------------------------------------------------------------------------
512------------------------------------------------------------------------------
508-- Functor
513-- Functor
509------------------------------------------------------------------------------
514------------------------------------------------------------------------------
510
515
511−instance Monad m => Functor (InterleavedT m) where
516+instance Monad m => Functor (CoserialT m) where
512− fmap f (InterleavedT (Stream m)) = InterleavedT $ Stream $ \_ stp yld ->
517+ fmap f (CoserialT (Stream m)) = CoserialT $ Stream $ \_ stp yld ->
513 let yield a Nothing = yld (f a) Nothing
518 let yield a Nothing = yld (f a) Nothing
514 yield a (Just r) =
519 yield a (Just r) =
515− yld (f a) (Just (getInterleavedT (fmap f (InterleavedT r))))
520+ yld (f a) (Just (getCoserialT (fmap f (CoserialT r))))
516 in m Nothing stp yield
521 in m Nothing stp yield
517
522
518------------------------------------------------------------------------------
523------------------------------------------------------------------------------
519-- Num
524-- Num
520------------------------------------------------------------------------------
525------------------------------------------------------------------------------
521
526
522−instance (Monad m, Num a) => Num (InterleavedT m a) where
527+instance (Monad m, Num a) => Num (CoserialT m a) where
523 fromInteger n = pure (fromInteger n)
528 fromInteger n = pure (fromInteger n)
524
529
525 negate = fmap negate
530 negate = fmap negate
@@ -530,14 +535,14 @@ instance (Monad m, Num a) => Num (InterleavedT m a) where
530 (*) = liftA2 (*)
535 (*) = liftA2 (*)
531 (-) = liftA2 (-)
536 (-) = liftA2 (-)
532
537
533−instance (Monad m, Fractional a) => Fractional (InterleavedT m a) where
538+instance (Monad m, Fractional a) => Fractional (CoserialT m a) where
534 fromRational n = pure (fromRational n)
539 fromRational n = pure (fromRational n)
535
540
536 recip = fmap recip
541 recip = fmap recip
537
542
538 (/) = liftA2 (/)
543 (/) = liftA2 (/)
539
544
540−instance (Monad m, Floating a) => Floating (InterleavedT m a) where
545+instance (Monad m, Floating a) => Floating (CoserialT m a) where
541 pi = pure pi
546 pi = pure pi
542
547
543 exp = fmap exp
548 exp = fmap exp
@@ -560,7 +565,7 @@ instance (Monad m, Floating a) => Floating (InterleavedT m a) where
560 logBase = liftA2 logBase
565 logBase = liftA2 logBase
561
566
562------------------------------------------------------------------------------
567------------------------------------------------------------------------------
563−-- AParallelT
568+-- CoparallelT
564------------------------------------------------------------------------------
569------------------------------------------------------------------------------
565
570
566-- | Adaptive parallel, in a left to right 'Semigroup' composition it tries to
571-- | Adaptive parallel, in a left to right 'Semigroup' composition it tries to
@@ -602,38 +607,38 @@ instance (Monad m, Floating a) => Floating (InterleavedT m a) where
602-- Note that this composition can be used to combine infinite number of streams
607-- 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.
608-- as it explores only a bounded number of streams at a time.
604--
609--
605−newtype AParallelT m a = AParallelT {getAParallelT :: Stream m a}
610+newtype CoparallelT m a = CoparallelT {getCoparallelT :: Stream m a}
606 deriving (MonadTrans)
611 deriving (MonadTrans)
607
612
608−deriving instance MonadAsync m => Monoid (AParallelT m a)
613+deriving instance MonadAsync m => Monoid (CoparallelT m a)
609−deriving instance MonadAsync m => Alternative (AParallelT m)
614+deriving instance MonadAsync m => Alternative (CoparallelT m)
610−deriving instance MonadAsync m => MonadPlus (AParallelT m)
615+deriving instance MonadAsync m => MonadPlus (CoparallelT m)
611−deriving instance MonadAsync m => MonadIO (AParallelT m)
616+deriving instance MonadAsync m => MonadIO (CoparallelT m)
612−deriving instance MonadAsync m => MonadThrow (AParallelT m)
617+deriving instance MonadAsync m => MonadThrow (CoparallelT m)
613−deriving instance (MonadBase b m, MonadAsync m) => MonadBase b (AParallelT m)
618+deriving instance (MonadBase b m, MonadAsync m) => MonadBase b (CoparallelT m)
614−deriving instance (MonadError e m, MonadAsync m) => MonadError e (AParallelT m)
619+deriving instance (MonadError e m, MonadAsync m) => MonadError e (CoparallelT m)
615−deriving instance (MonadReader r m, MonadAsync m) => MonadReader r (AParallelT m)
620+deriving instance (MonadReader r m, MonadAsync m) => MonadReader r (CoparallelT m)
616−deriving instance (MonadState s m, MonadAsync m) => MonadState s (AParallelT m)
621+deriving instance (MonadState s m, MonadAsync m) => MonadState s (CoparallelT m)
617
622
618−{-# DEPRECATED AsyncT "Please use 'AParallelT' instead." #-}
623+{-# DEPRECATED AsyncT "Please use 'CoparallelT' instead." #-}
619−type AsyncT = AParallelT
624+type AsyncT = CoparallelT
620
625
621−instance IsStream AParallelT where
626+instance IsStream CoparallelT where
622− toStream = getAParallelT
627+ toStream = getCoparallelT
623− fromStream = AParallelT
628+ fromStream = CoparallelT
624
629
625------------------------------------------------------------------------------
630------------------------------------------------------------------------------
626-- Semigroup
631-- Semigroup
627------------------------------------------------------------------------------
632------------------------------------------------------------------------------
628
633
629−-- | Polymorphic version of the 'Semigroup' operation '<>' of 'AParallelT', but
634+-- | Polymorphic version of the 'Semigroup' operation '<>' of 'CoparallelT', but
630-- polymorphic. Merges two streams possibly concurrently, preferring the
635-- polymorphic. Merges two streams possibly concurrently, preferring the
631-- elements from the left one when available.
636-- elements from the left one when available.
632{-# INLINE coparallel #-}
637{-# INLINE coparallel #-}
633coparallel :: (IsStream t, MonadAsync m) => t m a -> t m a -> t m a
638coparallel :: (IsStream t, MonadAsync m) => t m a -> t m a -> t m a
634coparallel m1 m2 = fromStream $ S.coparallel (toStream m1) (toStream m2)
639coparallel m1 m2 = fromStream $ S.coparallel (toStream m1) (toStream m2)
635
640
636−instance MonadAsync m => Semigroup (AParallelT m a) where
641+instance MonadAsync m => Semigroup (CoparallelT m a) where
637 (<>) = coparallel
642 (<>) = coparallel
638
643
639-- | Same as 'coparallel'.
644-- | Same as 'coparallel'.
@@ -661,35 +666,35 @@ parbind par m f = go m
661 yield a (Just r) = run $ f a `par` go r
666 yield a (Just r) = run $ f a `par` go r
662 in g Nothing stp yield
667 in g Nothing stp yield
663
668
664−instance MonadAsync m => Monad (AParallelT m) where
669+instance MonadAsync m => Monad (CoparallelT m) where
665 return = pure
670 return = pure
666− (AParallelT m) >>= f = AParallelT $ parbind par m g
671+ (CoparallelT m) >>= f = CoparallelT $ parbind par m g
667− where g x = getAParallelT (f x)
672+ where g x = getCoparallelT (f x)
668 par = S.joinStreamVar2 (SVarStyle Conjunction LIFO)
673 par = S.joinStreamVar2 (SVarStyle Conjunction LIFO)
669
674
670------------------------------------------------------------------------------
675------------------------------------------------------------------------------
671-- Applicative
676-- Applicative
672------------------------------------------------------------------------------
677------------------------------------------------------------------------------
673
678
674−instance MonadAsync m => Applicative (AParallelT m) where
679+instance MonadAsync m => Applicative (CoparallelT m) where
675− pure a = AParallelT $ S.cons a Nothing
680+ pure a = CoparallelT $ S.cons a Nothing
676 (<*>) = ap
681 (<*>) = ap
677
682
678------------------------------------------------------------------------------
683------------------------------------------------------------------------------
679-- Functor
684-- Functor
680------------------------------------------------------------------------------
685------------------------------------------------------------------------------
681
686
682−instance Monad m => Functor (AParallelT m) where
687+instance Monad m => Functor (CoparallelT m) where
683− fmap f (AParallelT (Stream m)) = AParallelT $ Stream $ \_ stp yld ->
688+ fmap f (CoparallelT (Stream m)) = CoparallelT $ Stream $ \_ stp yld ->
684 let yield a Nothing = yld (f a) Nothing
689 let yield a Nothing = yld (f a) Nothing
685− yield a (Just r) = yld (f a) (Just (getAParallelT (fmap f (AParallelT r))))
690+ yield a (Just r) = yld (f a) (Just (getCoparallelT (fmap f (CoparallelT r))))
686 in m Nothing stp yield
691 in m Nothing stp yield
687
692
688------------------------------------------------------------------------------
693------------------------------------------------------------------------------
689-- Num
694-- Num
690------------------------------------------------------------------------------
695------------------------------------------------------------------------------
691
696
692−instance (MonadAsync m, Num a) => Num (AParallelT m a) where
697+instance (MonadAsync m, Num a) => Num (CoparallelT m a) where
693 fromInteger n = pure (fromInteger n)
698 fromInteger n = pure (fromInteger n)
694
699
695 negate = fmap negate
700 negate = fmap negate
@@ -700,14 +705,14 @@ instance (MonadAsync m, Num a) => Num (AParallelT m a) where
700 (*) = liftA2 (*)
705 (*) = liftA2 (*)
701 (-) = liftA2 (-)
706 (-) = liftA2 (-)
702
707
703−instance (MonadAsync m, Fractional a) => Fractional (AParallelT m a) where
708+instance (MonadAsync m, Fractional a) => Fractional (CoparallelT m a) where
704 fromRational n = pure (fromRational n)
709 fromRational n = pure (fromRational n)
705
710
706 recip = fmap recip
711 recip = fmap recip
707
712
708 (/) = liftA2 (/)
713 (/) = liftA2 (/)
709
714
710−instance (MonadAsync m, Floating a) => Floating (AParallelT m a) where
715+instance (MonadAsync m, Floating a) => Floating (CoparallelT m a) where
711 pi = pure pi
716 pi = pure pi
712
717
713 exp = fmap exp
718 exp = fmap exp
@@ -764,7 +769,7 @@ instance (MonadAsync m, Floating a) => Floating (AParallelT m a) where
764-- ThreadId 38: Delay 3
769-- ThreadId 38: Delay 3
765-- @
770-- @
766--
771--
767−-- Unlike 'AParallelT' all iterations are guaranteed to run fairly
772+-- Unlike 'CoparallelT' all iterations are guaranteed to run fairly
768-- concurrently, unconditionally.
773-- concurrently, unconditionally.
769--
774--
770-- Note that round robin composition can only combine a finite number of
775-- Note that round robin composition can only combine a finite number of
@@ -1073,17 +1078,22 @@ adapt = fromStream . toStream
1073serially :: IsStream t => SerialT m a -> t m a
1078serially :: IsStream t => SerialT m a -> t m a
1074serially = adapt
1079serially = adapt
1075
1080
1076−-- | Fix the type of a polymorphic stream as 'InterleavedT'.
1081+-- | Fix the type of a polymorphic stream as 'CoserialT'.
1077−coserially :: IsStream t => InterleavedT m a -> t m a
1082+coserially :: IsStream t => CoserialT m a -> t m a
1078coserially = adapt
1083coserially = adapt
1079
1084
1085+-- | Same as 'coserially'.
1086+{-# DEPRECATED interleaving "Please use coserially instead." #-}
1087+interleaving :: IsStream t => CoserialT m a -> t m a
1088+interleaving = coserially
1089+
1080−-- | Fix the type of a polymorphic stream as 'AParallelT'.
1090+-- | Fix the type of a polymorphic stream as 'CoparallelT'.
1081−coparallely :: IsStream t => AParallelT m a -> t m a
1091+coparallely :: IsStream t => CoparallelT m a -> t m a
1082coparallely = adapt
1092coparallely = adapt
1083
1093
1084-- | Same as 'coparallely'.
1094-- | Same as 'coparallely'.
1085{-# DEPRECATED asyncly "Please use coparallely instead." #-}
1095{-# DEPRECATED asyncly "Please use coparallely instead." #-}
1086−asyncly :: IsStream t => AParallelT m a -> t m a
1096+asyncly :: IsStream t => CoparallelT m a -> t m a
1087asyncly = coparallely
1097asyncly = coparallely
1088
1098
1089-- | Fix the type of a polymorphic stream as 'ParallelT'.
1099-- | Fix the type of a polymorphic stream as 'ParallelT'.
@@ -1114,7 +1124,7 @@ runInterleavedT = runStream . coserially
1114
1124
1115-- | Same as @runStream . coparallely@.
1125-- | Same as @runStream . coparallely@.
1116{-# DEPRECATED runAsyncT "Please use 'runStream . coparallely' instead." #-}
1126{-# DEPRECATED runAsyncT "Please use 'runStream . coparallely' instead." #-}
1117−runAsyncT :: Monad m => AParallelT m a -> m ()
1127+runAsyncT :: Monad m => CoparallelT m a -> m ()
1118runAsyncT = runStream . coparallely
1128runAsyncT = runStream . coparallely
1119
1129
1120-- | Same as @runStream . parallely@.
1130-- | Same as @runStream . parallely@.
test/Main.hs+2−2
@@ -19,10 +19,10 @@ 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]
23toListInterleaved = A.toList . coserially
23toListInterleaved = A.toList . coserially
24
24
25−toListAsync :: AParallelT IO a -> IO [a]
25+toListAsync :: CoparallelT IO a -> IO [a]
26toListAsync = A.toList . coparallely
26toListAsync = A.toList . coparallely
27
27
28toListParallel :: ParallelT IO a -> IO [a]
28toListParallel :: ParallelT IO a -> IO [a]