@@ -58,8 +58,9 @@ module Streamly.Streams
5858 -- * Stream Styles
5959 , SerialT
6060 , StreamT -- deprecated
61− , InterleavedT
62− , AParallelT
61+ , CoserialT
62+ , InterleavedT -- deprecated
63+ , CoparallelT
6364 , AsyncT -- deprecated
6465 , ParallelT
6566 , ZipSerial
@@ -69,6 +70,7 @@ module Streamly.Streams
6970 -- * Type Adapters
7071 , serially
7172 , coserially
73+ , interleaving -- deprecated
7274 , coparallely
7375 , asyncly -- deprecated
7476 , parallely
@@ -416,10 +418,10 @@ instance (Monad m, Floating a) => Floating (SerialT m a) where
416418 logBase = liftA2 logBase
417419
418420------------------------------------------------------------------------------
419−-- InterleavedT
421+-- CoserialT
420422------------------------------------------------------------------------------
421423
422−-- | The 'Semigroup' instance of 'InterleavedT' interleaves two streams,
424+-- | The 'Semigroup' instance of 'CoserialT' interleaves two streams,
423425-- yielding one element from each stream alternately.
424426--
425427-- @
@@ -449,31 +451,34 @@ instance (Monad m, Floating a) => Floating (SerialT m a) where
449451-- Note that interleaving composition can only combine a finite number of
450452-- streams as it needs to retain state for each unfinished stream.
451453--
452−newtype InterleavedT m a = InterleavedT {getInterleavedT :: Stream m a}
454+newtype CoserialT m a = CoserialT {getCoserialT :: Stream m a}
453455 deriving (Monoid, MonadTrans, MonadIO, MonadThrow)
454456
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)
457+deriving instance MonadAsync m => Alternative (CoserialT m)
458+deriving instance MonadAsync m => MonadPlus (CoserialT m)
459+deriving instance (MonadBase b m, Monad m) => MonadBase b (CoserialT m)
460+deriving instance MonadError e m => MonadError e (CoserialT m)
461+deriving instance MonadReader r m => MonadReader r (CoserialT m)
462+deriving instance MonadState s m => MonadState s (CoserialT m)
461463
462−instance IsStream InterleavedT where
463− toStream = getInterleavedT
464− fromStream = InterleavedT
464+{-# DEPRECATED InterleavedT "Please use 'CoserialT' instead." #-}
465+type InterleavedT = CoserialT
466+
467+instance IsStream CoserialT where
468+ toStream = getCoserialT
469+ fromStream = CoserialT
465470
466471------------------------------------------------------------------------------
467472-- Semigroup
468473------------------------------------------------------------------------------
469474
470−-- | Polymorphic version of the 'Semigroup' operation '<>' of 'InterleavedT'.
475+-- | Polymorphic version of the 'Semigroup' operation '<>' of 'CoserialT'.
471476-- Interleaves two streams, yielding one element from each stream alternately.
472477{-# INLINE coserial #-}
473478coserial :: IsStream t => t m a -> t m a -> t m a
474479coserial m1 m2 = fromStream $ S.coserial (toStream m1) (toStream m2)
475480
476−instance Semigroup (InterleavedT m a) where
481+instance Semigroup (CoserialT m a) where
477482 (<>) = coserial
478483
479484infixr 5 <=>
@@ -488,9 +493,9 @@ infixr 5 <=>
488493-- Monad
489494------------------------------------------------------------------------------
490495
491−instance Monad m => Monad (InterleavedT m) where
496+instance Monad m => Monad (CoserialT m) where
492497 return = pure
493− (InterleavedT (Stream m)) >>= f = InterleavedT $ Stream $ \_ stp yld ->
498+ (CoserialT (Stream m)) >>= f = CoserialT $ Stream $ \_ stp yld ->
494499 let run x = (S.runStream x) Nothing stp yld
495500 yield a Nothing = run $ toStream (f a)
496501 yield a (Just r) = run $ toStream $ f a <> (fromStream r >>= f)
@@ -500,26 +505,26 @@ instance Monad m => Monad (InterleavedT m) where
500505-- Applicative
501506------------------------------------------------------------------------------
502507
503−instance Monad m => Applicative (InterleavedT m) where
504− pure a = InterleavedT $ S.cons a Nothing
508+instance Monad m => Applicative (CoserialT m) where
509+ pure a = CoserialT $ S.cons a Nothing
505510 (<*>) = ap
506511
507512------------------------------------------------------------------------------
508513-- Functor
509514------------------------------------------------------------------------------
510515
511−instance Monad m => Functor (InterleavedT m) where
512− fmap f (InterleavedT (Stream m)) = InterleavedT $ Stream $ \_ stp yld ->
516+instance Monad m => Functor (CoserialT m) where
517+ fmap f (CoserialT (Stream m)) = CoserialT $ Stream $ \_ stp yld ->
513518 let yield a Nothing = yld (f a) Nothing
514519 yield a (Just r) =
515− yld (f a) (Just (getInterleavedT (fmap f (InterleavedT r))))
520+ yld (f a) (Just (getCoserialT (fmap f (CoserialT r))))
516521 in m Nothing stp yield
517522
518523------------------------------------------------------------------------------
519524-- Num
520525------------------------------------------------------------------------------
521526
522−instance (Monad m, Num a) => Num (InterleavedT m a) where
527+instance (Monad m, Num a) => Num (CoserialT m a) where
523528 fromInteger n = pure (fromInteger n)
524529
525530 negate = fmap negate
@@ -530,14 +535,14 @@ instance (Monad m, Num a) => Num (InterleavedT m a) where
530535 (*) = liftA2 (*)
531536 (-) = liftA2 (-)
532537
533−instance (Monad m, Fractional a) => Fractional (InterleavedT m a) where
538+instance (Monad m, Fractional a) => Fractional (CoserialT m a) where
534539 fromRational n = pure (fromRational n)
535540
536541 recip = fmap recip
537542
538543 (/) = liftA2 (/)
539544
540−instance (Monad m, Floating a) => Floating (InterleavedT m a) where
545+instance (Monad m, Floating a) => Floating (CoserialT m a) where
541546 pi = pure pi
542547
543548 exp = fmap exp
@@ -560,7 +565,7 @@ instance (Monad m, Floating a) => Floating (InterleavedT m a) where
560565 logBase = liftA2 logBase
561566
562567------------------------------------------------------------------------------
563−-- AParallelT
568+-- CoparallelT
564569------------------------------------------------------------------------------
565570
566571-- | 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
602607-- Note that this composition can be used to combine infinite number of streams
603608-- as it explores only a bounded number of streams at a time.
604609--
605−newtype AParallelT m a = AParallelT {getAParallelT :: Stream m a}
610+newtype CoparallelT m a = CoparallelT {getCoparallelT :: Stream m a}
606611 deriving (MonadTrans)
607612
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)
613+deriving instance MonadAsync m => Monoid (CoparallelT m a)
614+deriving instance MonadAsync m => Alternative (CoparallelT m)
615+deriving instance MonadAsync m => MonadPlus (CoparallelT m)
616+deriving instance MonadAsync m => MonadIO (CoparallelT m)
617+deriving instance MonadAsync m => MonadThrow (CoparallelT m)
618+deriving instance (MonadBase b m, MonadAsync m) => MonadBase b (CoparallelT m)
619+deriving instance (MonadError e m, MonadAsync m) => MonadError e (CoparallelT m)
620+deriving instance (MonadReader r m, MonadAsync m) => MonadReader r (CoparallelT m)
621+deriving instance (MonadState s m, MonadAsync m) => MonadState s (CoparallelT m)
617622
618−{-# DEPRECATED AsyncT "Please use 'AParallelT' instead." #-}
619−type AsyncT = AParallelT
623+{-# DEPRECATED AsyncT "Please use 'CoparallelT' instead." #-}
624+type AsyncT = CoparallelT
620625
621−instance IsStream AParallelT where
622− toStream = getAParallelT
623− fromStream = AParallelT
626+instance IsStream CoparallelT where
627+ toStream = getCoparallelT
628+ fromStream = CoparallelT
624629
625630------------------------------------------------------------------------------
626631-- Semigroup
627632------------------------------------------------------------------------------
628633
629−-- | Polymorphic version of the 'Semigroup' operation '<>' of 'AParallelT', but
634+-- | Polymorphic version of the 'Semigroup' operation '<>' of 'CoparallelT', but
630635-- polymorphic. Merges two streams possibly concurrently, preferring the
631636-- elements from the left one when available.
632637{-# INLINE coparallel #-}
633638coparallel :: (IsStream t, MonadAsync m) => t m a -> t m a -> t m a
634639coparallel m1 m2 = fromStream $ S.coparallel (toStream m1) (toStream m2)
635640
636−instance MonadAsync m => Semigroup (AParallelT m a) where
641+instance MonadAsync m => Semigroup (CoparallelT m a) where
637642 (<>) = coparallel
638643
639644-- | Same as 'coparallel'.
@@ -661,35 +666,35 @@ parbind par m f = go m
661666 yield a (Just r) = run $ f a `par` go r
662667 in g Nothing stp yield
663668
664−instance MonadAsync m => Monad (AParallelT m) where
669+instance MonadAsync m => Monad (CoparallelT m) where
665670 return = pure
666− (AParallelT m) >>= f = AParallelT $ parbind par m g
667− where g x = getAParallelT (f x)
671+ (CoparallelT m) >>= f = CoparallelT $ parbind par m g
672+ where g x = getCoparallelT (f x)
668673 par = S.joinStreamVar2 (SVarStyle Conjunction LIFO)
669674
670675------------------------------------------------------------------------------
671676-- Applicative
672677------------------------------------------------------------------------------
673678
674−instance MonadAsync m => Applicative (AParallelT m) where
675− pure a = AParallelT $ S.cons a Nothing
679+instance MonadAsync m => Applicative (CoparallelT m) where
680+ pure a = CoparallelT $ S.cons a Nothing
676681 (<*>) = ap
677682
678683------------------------------------------------------------------------------
679684-- Functor
680685------------------------------------------------------------------------------
681686
682−instance Monad m => Functor (AParallelT m) where
683− fmap f (AParallelT (Stream m)) = AParallelT $ Stream $ \_ stp yld ->
687+instance Monad m => Functor (CoparallelT m) where
688+ fmap f (CoparallelT (Stream m)) = CoparallelT $ Stream $ \_ stp yld ->
684689 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))))
686691 in m Nothing stp yield
687692
688693------------------------------------------------------------------------------
689694-- Num
690695------------------------------------------------------------------------------
691696
692−instance (MonadAsync m, Num a) => Num (AParallelT m a) where
697+instance (MonadAsync m, Num a) => Num (CoparallelT m a) where
693698 fromInteger n = pure (fromInteger n)
694699
695700 negate = fmap negate
@@ -700,14 +705,14 @@ instance (MonadAsync m, Num a) => Num (AParallelT m a) where
700705 (*) = liftA2 (*)
701706 (-) = liftA2 (-)
702707
703−instance (MonadAsync m, Fractional a) => Fractional (AParallelT m a) where
708+instance (MonadAsync m, Fractional a) => Fractional (CoparallelT m a) where
704709 fromRational n = pure (fromRational n)
705710
706711 recip = fmap recip
707712
708713 (/) = liftA2 (/)
709714
710−instance (MonadAsync m, Floating a) => Floating (AParallelT m a) where
715+instance (MonadAsync m, Floating a) => Floating (CoparallelT m a) where
711716 pi = pure pi
712717
713718 exp = fmap exp
@@ -764,7 +769,7 @@ instance (MonadAsync m, Floating a) => Floating (AParallelT m a) where
764769-- ThreadId 38: Delay 3
765770-- @
766771--
767−-- Unlike 'AParallelT' all iterations are guaranteed to run fairly
772+-- Unlike 'CoparallelT' all iterations are guaranteed to run fairly
768773-- concurrently, unconditionally.
769774--
770775-- Note that round robin composition can only combine a finite number of
@@ -1073,17 +1078,22 @@ adapt = fromStream . toStream
10731078serially :: IsStream t => SerialT m a -> t m a
10741079serially = adapt
10751080
1076−-- | Fix the type of a polymorphic stream as 'InterleavedT'.
1077−coserially :: IsStream t => InterleavedT m a -> t m a
1081+-- | Fix the type of a polymorphic stream as 'CoserialT'.
1082+coserially :: IsStream t => CoserialT m a -> t m a
10781083coserially = adapt
10791084
1080−-- | Fix the type of a polymorphic stream as 'AParallelT'.
1081−coparallely :: IsStream t => AParallelT m a -> t m a
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+
1090+-- | Fix the type of a polymorphic stream as 'CoparallelT'.
1091+coparallely :: IsStream t => CoparallelT m a -> t m a
10821092coparallely = adapt
10831093
10841094-- | Same as 'coparallely'.
10851095{-# 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
10871097asyncly = coparallely
10881098
10891099-- | Fix the type of a polymorphic stream as 'ParallelT'.
@@ -1114,7 +1124,7 @@ runInterleavedT = runStream . coserially
11141124
11151125-- | Same as @runStream . coparallely@.
11161126{-# DEPRECATED runAsyncT "Please use 'runStream . coparallely' instead." #-}
1117−runAsyncT :: Monad m => AParallelT m a -> m ()
1127+runAsyncT :: Monad m => CoparallelT m a -> m ()
11181128runAsyncT = runStream . coparallely
11191129
11201130-- | Same as @runStream . parallely@.