@@ -58,8 +58,9 @@ module Streamly.Streams
58 -- * Stream Styles
58 -- * Stream Styles
60 , StreamT -- deprecated
60 , StreamT -- deprecated
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
418------------------------------------------------------------------------------
420------------------------------------------------------------------------------
419−-- InterleavedT
421+-- CoserialT
420------------------------------------------------------------------------------
422------------------------------------------------------------------------------
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.
@@ -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.
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)
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)
464+{-# DEPRECATED InterleavedT "Please use 'CoserialT' instead." #-}
465+type InterleavedT = CoserialT
462−instance IsStream InterleavedT where
467+instance IsStream CoserialT where
463− toStream = getInterleavedT
468+ toStream = getCoserialT
464− fromStream = InterleavedT
469+ fromStream = CoserialT
466------------------------------------------------------------------------------
471------------------------------------------------------------------------------
467-- Semigroup
472-- Semigroup
468------------------------------------------------------------------------------
473------------------------------------------------------------------------------
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)
476−instance Semigroup (InterleavedT m a) where
481+instance Semigroup (CoserialT m a) where
477 (<>) = coserial
482 (<>) = coserial
479infixr 5 <=>
484infixr 5 <=>
@@ -488,9 +493,9 @@ infixr 5 <=>
489------------------------------------------------------------------------------
494------------------------------------------------------------------------------
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------------------------------------------------------------------------------
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
507------------------------------------------------------------------------------
512------------------------------------------------------------------------------
508-- Functor
513-- Functor
509------------------------------------------------------------------------------
514------------------------------------------------------------------------------
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
518------------------------------------------------------------------------------
523------------------------------------------------------------------------------
520------------------------------------------------------------------------------
525------------------------------------------------------------------------------
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)
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 (-)
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)
536 recip = fmap recip
541 recip = fmap recip
538 (/) = liftA2 (/)
543 (/) = liftA2 (/)
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
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
562------------------------------------------------------------------------------
567------------------------------------------------------------------------------
563−-- AParallelT
568+-- CoparallelT
564------------------------------------------------------------------------------
569------------------------------------------------------------------------------
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.
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)
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)
618−{-# DEPRECATED AsyncT "Please use 'AParallelT' instead." #-}
623+{-# DEPRECATED AsyncT "Please use 'CoparallelT' instead." #-}
619−type AsyncT = AParallelT
624+type AsyncT = CoparallelT
621−instance IsStream AParallelT where
626+instance IsStream CoparallelT where
622− toStream = getAParallelT
627+ toStream = getCoparallelT
623− fromStream = AParallelT
628+ fromStream = CoparallelT
625------------------------------------------------------------------------------
630------------------------------------------------------------------------------
626-- Semigroup
631-- Semigroup
627------------------------------------------------------------------------------
632------------------------------------------------------------------------------
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)
636−instance MonadAsync m => Semigroup (AParallelT m a) where
641+instance MonadAsync m => Semigroup (CoparallelT m a) where
637 (<>) = coparallel
642 (<>) = coparallel
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
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)
670------------------------------------------------------------------------------
675------------------------------------------------------------------------------
671-- Applicative
676-- Applicative
672------------------------------------------------------------------------------
677------------------------------------------------------------------------------
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
678------------------------------------------------------------------------------
683------------------------------------------------------------------------------
679-- Functor
684-- Functor
680------------------------------------------------------------------------------
685------------------------------------------------------------------------------
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
688------------------------------------------------------------------------------
693------------------------------------------------------------------------------
690------------------------------------------------------------------------------
695------------------------------------------------------------------------------
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)
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 (-)
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)
706 recip = fmap recip
711 recip = fmap recip
708 (/) = liftA2 (/)
713 (/) = liftA2 (/)
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
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
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.
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
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
1085+-- | Same as 'coserially'.
1086+{-# DEPRECATED interleaving "Please use coserially instead." #-}
1087+interleaving :: IsStream t => CoserialT m a -> t m a
1088+interleaving = coserially
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
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
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
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
1120-- | Same as @runStream . parallely@.
1130-- | Same as @runStream . parallely@.