@@ -21,7 +21,8 @@ module Streamly.Streams
22 IsStream (..)
22 IsStream (..)
23 , Streaming -- deprecated
23 , Streaming -- deprecated
24− , MonadAsync
25+ , S.MonadAsync -- deprecated
26 -- * SVars
27 -- * SVars
27 , SVarSched (..)
28 , SVarSched (..)
@@ -48,9 +49,9 @@ module Streamly.Streams
50 -- * Merging Streams
51 -- * Merging Streams
52− , interleave
53+ , coserial
53− , aparallel
54+ , coparallel
54 , parallel
55 , parallel
55 , (<=>) --deprecated
56 , (<=>) --deprecated
56 , (<|) --deprecated
57 , (<|) --deprecated
@@ -58,22 +59,27 @@ module Streamly.Streams
58 -- * Stream Styles
59 -- * Stream Styles
60 , StreamT -- deprecated
61 , StreamT -- deprecated
61− , InterleavedT
63+ , InterleavedT -- deprecated
62− , AParallelT
64+ , CoparallelT
63 , AsyncT -- deprecated
65 , AsyncT -- deprecated
64 , ParallelT
66 , ParallelT
65 , ZipSerial
67 , ZipSerial
66 , ZipStream -- deprecated
68 , ZipStream -- deprecated
67− , ZipAsync
70+ , ZipAsync -- deprecated
69 -- * Type Adapters
72 -- * Type Adapters
70 , serially
73 , serially
71− , interleaving
75+ , interleaving -- deprecated
72− , aparallely
76+ , coparallely
73 , asyncly -- deprecated
77 , asyncly -- deprecated
74 , parallely
78 , parallely
75− , zipping
80+ , zipping -- deprecated
76− , zippingAsync
82+ , zippingAsync -- deprecated
79 -- * Running Streams
85 -- * Running Streams
@@ -86,10 +92,10 @@ module Streamly.Streams
87 -- * Zipping
93 -- * Zipping
89− , zipAsyncWith
96+ , zipAsyncWith -- deprecated
91 -- * Fold Utilities
98 -- * Fold Utilities
93 , foldWith
99 , foldWith
94 , foldMapWith
100 , foldMapWith
95 , forEachWith
101 , forEachWith
@@ -107,7 +113,7 @@ import Control.Monad.State.Class (MonadState(..))
107import Control.Monad.Trans.Class (MonadTrans)
113import Control.Monad.Trans.Class (MonadTrans)
108import Data.Semigroup (Semigroup(..))
114import Data.Semigroup (Semigroup(..))
109import Prelude hiding (zipWith)
115import Prelude hiding (zipWith)
110−import Streamly.Core ( MonadAsync, Stream(Stream)
116+import Streamly.Core ( MonadParallel, Stream(Stream)
111 , SVar, SVarStyle(..)
117 , SVar, SVarStyle(..)
112 , SVarTag(..), SVarSched(..))
118 , SVarTag(..), SVarSched(..))
113import qualified Streamly.Core as S
119import qualified Streamly.Core as S
@@ -199,7 +205,7 @@ fromCallback :: IsStream t => (forall r. (a -> m r) -> m r) -> t m a
199fromCallback k = fromStream $ Stream $ \_ _ yld -> k (\a -> yld a Nothing)
205fromCallback k = fromStream $ Stream $ \_ _ yld -> k (\a -> yld a Nothing)
201-- | Read an SVar to get a stream.
207-- | Read an SVar to get a stream.
202−fromSVar :: (MonadAsync m, IsStream t) => SVar m a -> t m a
208+fromSVar :: (MonadParallel m, IsStream t) => SVar m a -> t m a
203fromSVar sv = fromStream $ S.fromStreamVar sv
209fromSVar sv = fromStream $ S.fromStreamVar sv
205------------------------------------------------------------------------------
211------------------------------------------------------------------------------
@@ -216,7 +222,9 @@ streamFold sv step blank m =
216 yield a (Just x) = step a (Just (fromStream x))
222 yield a (Just x) = step a (Just (fromStream x))
217 in (S.runStream (toStream m)) sv blank yield
223 in (S.runStream (toStream m)) sv blank yield
219−-- | Run a streaming composition, discard the results.
225+-- | Run a streaming composition, discard the results. By default it interprets
226+-- the stream as 'SerialT', to run other types of streams use the type adapting
227+-- combinators for example @runStream . 'parallely'@.
220runStream :: Monad m => SerialT m a -> m ()
228runStream :: Monad m => SerialT m a -> m ()
221runStream m = go (toStream m)
229runStream m = go (toStream m)
@@ -233,7 +241,7 @@ runStreaming = runStream . adapt
234-- | Write a stream to an 'SVar' in a non-blocking manner. The stream can then
242-- | Write a stream to an 'SVar' in a non-blocking manner. The stream can then
235-- be read back from the SVar using 'fromSVar'.
243-- be read back from the SVar using 'fromSVar'.
236−toSVar :: (IsStream t, MonadAsync m) => SVar m a -> t m a -> m ()
244+toSVar :: (IsStream t, MonadParallel m) => SVar m a -> t m a -> m ()
237toSVar sv m = S.toStreamVar sv (toStream m)
245toSVar sv m = S.toStreamVar sv (toStream m)
239------------------------------------------------------------------------------
247------------------------------------------------------------------------------
@@ -247,7 +255,7 @@ toSVar sv m = S.toStreamVar sv (toStream m)
247-- not drained fully we may have a thread blocked forever and once exhausted it
255-- not drained fully we may have a thread blocked forever and once exhausted it
248-- will always return 'empty'.
256-- will always return 'empty'.
250−async :: (IsStream t, MonadAsync m) => t m a -> m (t m a)
258+async :: (IsStream t, MonadParallel m) => t m a -> m (t m a)
251async m = do
259async m = do
252 sv <- S.newStreamVar1 (SVarStyle Disjunction LIFO) (toStream m)
260 sv <- S.newStreamVar1 (SVarStyle Disjunction LIFO) (toStream m)
253 return $ fromSVar sv
261 return $ fromSVar sv
@@ -309,8 +317,8 @@ async m = do
309newtype SerialT m a = SerialT {getSerialT :: Stream m a}
317newtype SerialT m a = SerialT {getSerialT :: Stream m a}
310 deriving (Semigroup, Monoid, MonadTrans, MonadIO, MonadThrow)
318 deriving (Semigroup, Monoid, MonadTrans, MonadIO, MonadThrow)
312−deriving instance MonadAsync m => Alternative (SerialT m)
320+deriving instance MonadParallel m => Alternative (SerialT m)
313−deriving instance MonadAsync m => MonadPlus (SerialT m)
321+deriving instance MonadParallel m => MonadPlus (SerialT m)
314deriving instance (MonadBase b m, Monad m) => MonadBase b (SerialT m)
322deriving instance (MonadBase b m, Monad m) => MonadBase b (SerialT m)
315deriving instance MonadError e m => MonadError e (SerialT m)
323deriving instance MonadError e m => MonadError e (SerialT m)
316deriving instance MonadReader r m => MonadReader r (SerialT m)
324deriving instance MonadReader r m => MonadReader r (SerialT m)
@@ -336,9 +344,9 @@ type StreamT = SerialT
336-- | Polymorphic version of the 'Semigroup' operation '<>' of 'SerialT'.
344-- | Polymorphic version of the 'Semigroup' operation '<>' of 'SerialT'.
337-- Appends two streams sequentially, yielding all elements from the first
345-- Appends two streams sequentially, yielding all elements from the first
338-- stream, and then all elements from the second stream.
346-- stream, and then all elements from the second stream.
339−{-# INLINE append #-}
347+{-# INLINE serial #-}
340−append :: IsStream t => t m a -> t m a -> t m a
348+serial :: IsStream t => t m a -> t m a -> t m a
341−append m1 m2 = fromStream $ S.append (toStream m1) (toStream m2)
349+serial m1 m2 = fromStream $ S.serial (toStream m1) (toStream m2)
343------------------------------------------------------------------------------
351------------------------------------------------------------------------------
@@ -416,10 +424,10 @@ instance (Monad m, Floating a) => Floating (SerialT m a) where
416 logBase = liftA2 logBase
424 logBase = liftA2 logBase
418------------------------------------------------------------------------------
426------------------------------------------------------------------------------
419−-- InterleavedT
427+-- CoserialT
420------------------------------------------------------------------------------
428------------------------------------------------------------------------------
422−-- | The 'Semigroup' instance of 'InterleavedT' interleaves two streams,
430+-- | The 'Semigroup' instance of 'CoserialT' interleaves two streams,
423-- yielding one element from each stream alternately.
431-- yielding one element from each stream alternately.
@@ -449,48 +457,51 @@ instance (Monad m, Floating a) => Floating (SerialT m a) where
449-- Note that interleaving composition can only combine a finite number of
457-- Note that interleaving composition can only combine a finite number of
450-- streams as it needs to retain state for each unfinished stream.
458-- streams as it needs to retain state for each unfinished stream.
452−newtype InterleavedT m a = InterleavedT {getInterleavedT :: Stream m a}
460+newtype CoserialT m a = CoserialT {getCoserialT :: Stream m a}
453 deriving (Monoid, MonadTrans, MonadIO, MonadThrow)
461 deriving (Monoid, MonadTrans, MonadIO, MonadThrow)
455−deriving instance MonadAsync m => Alternative (InterleavedT m)
463+deriving instance MonadParallel m => Alternative (CoserialT m)
456−deriving instance MonadAsync m => MonadPlus (InterleavedT m)
464+deriving instance MonadParallel m => MonadPlus (CoserialT m)
457−deriving instance (MonadBase b m, Monad m) => MonadBase b (InterleavedT m)
465+deriving instance (MonadBase b m, Monad m) => MonadBase b (CoserialT m)
458−deriving instance MonadError e m => MonadError e (InterleavedT m)
466+deriving instance MonadError e m => MonadError e (CoserialT m)
459−deriving instance MonadReader r m => MonadReader r (InterleavedT m)
467+deriving instance MonadReader r m => MonadReader r (CoserialT m)
460−deriving instance MonadState s m => MonadState s (InterleavedT m)
468+deriving instance MonadState s m => MonadState s (CoserialT m)
470+{-# DEPRECATED InterleavedT "Please use 'CoserialT' instead." #-}
471+type InterleavedT = CoserialT
462−instance IsStream InterleavedT where
473+instance IsStream CoserialT where
463− toStream = getInterleavedT
474+ toStream = getCoserialT
464− fromStream = InterleavedT
475+ fromStream = CoserialT
466------------------------------------------------------------------------------
477------------------------------------------------------------------------------
467-- Semigroup
478-- Semigroup
468------------------------------------------------------------------------------
479------------------------------------------------------------------------------
470−-- | Polymorphic version of the 'Semigroup' operation '<>' of 'InterleavedT'.
481+-- | Polymorphic version of the 'Semigroup' operation '<>' of 'CoserialT'.
471-- Interleaves two streams, yielding one element from each stream alternately.
482-- Interleaves two streams, yielding one element from each stream alternately.
472−{-# INLINE interleave #-}
483+{-# INLINE coserial #-}
473−interleave :: IsStream t => t m a -> t m a -> t m a
484+coserial :: IsStream t => t m a -> t m a -> t m a
474−interleave m1 m2 = fromStream $ S.interleave (toStream m1) (toStream m2)
485+coserial m1 m2 = fromStream $ S.coserial (toStream m1) (toStream m2)
476−instance Semigroup (InterleavedT m a) where
487+instance Semigroup (CoserialT m a) where
477− (<>) = interleave
488+ (<>) = coserial
479infixr 5 <=>
490infixr 5 <=>
481−-- | Same as 'interleave'.
492+-- | Same as 'coserial'.
482−{-# Deprecated (<=>) "Please use '<>' of InterleavedT or 'interleave' instead." #-}
493+{-# DEPRECATED (<=>) "Please use 'coserial' instead." #-}
483{-# INLINE (<=>) #-}
494{-# INLINE (<=>) #-}
484(<=>) :: IsStream t => t m a -> t m a -> t m a
495(<=>) :: IsStream t => t m a -> t m a -> t m a
485−(<=>) = interleave
496+(<=>) = coserial
487------------------------------------------------------------------------------
498------------------------------------------------------------------------------
489------------------------------------------------------------------------------
500------------------------------------------------------------------------------
491−instance Monad m => Monad (InterleavedT m) where
502+instance Monad m => Monad (CoserialT m) where
492 return = pure
503 return = pure
493− (InterleavedT (Stream m)) >>= f = InterleavedT $ Stream $ \_ stp yld ->
504+ (CoserialT (Stream m)) >>= f = CoserialT $ Stream $ \_ stp yld ->
494 let run x = (S.runStream x) Nothing stp yld
505 let run x = (S.runStream x) Nothing stp yld
495 yield a Nothing = run $ toStream (f a)
506 yield a Nothing = run $ toStream (f a)
496 yield a (Just r) = run $ toStream $ f a <> (fromStream r >>= f)
507 yield a (Just r) = run $ toStream $ f a <> (fromStream r >>= f)
@@ -500,26 +511,26 @@ instance Monad m => Monad (InterleavedT m) where
500-- Applicative
511-- Applicative
501------------------------------------------------------------------------------
512------------------------------------------------------------------------------
503−instance Monad m => Applicative (InterleavedT m) where
514+instance Monad m => Applicative (CoserialT m) where
504− pure a = InterleavedT $ S.cons a Nothing
515+ pure a = CoserialT $ S.cons a Nothing
505 (<*>) = ap
516 (<*>) = ap
507------------------------------------------------------------------------------
518------------------------------------------------------------------------------
508-- Functor
519-- Functor
509------------------------------------------------------------------------------
520------------------------------------------------------------------------------
511−instance Monad m => Functor (InterleavedT m) where
522+instance Monad m => Functor (CoserialT m) where
512− fmap f (InterleavedT (Stream m)) = InterleavedT $ Stream $ \_ stp yld ->
523+ fmap f (CoserialT (Stream m)) = CoserialT $ Stream $ \_ stp yld ->
513 let yield a Nothing = yld (f a) Nothing
524 let yield a Nothing = yld (f a) Nothing
514 yield a (Just r) =
525 yield a (Just r) =
515− yld (f a) (Just (getInterleavedT (fmap f (InterleavedT r))))
526+ yld (f a) (Just (getCoserialT (fmap f (CoserialT r))))
516 in m Nothing stp yield
527 in m Nothing stp yield
518------------------------------------------------------------------------------
529------------------------------------------------------------------------------
520------------------------------------------------------------------------------
531------------------------------------------------------------------------------
522−instance (Monad m, Num a) => Num (InterleavedT m a) where
533+instance (Monad m, Num a) => Num (CoserialT m a) where
523 fromInteger n = pure (fromInteger n)
534 fromInteger n = pure (fromInteger n)
525 negate = fmap negate
536 negate = fmap negate
@@ -530,14 +541,14 @@ instance (Monad m, Num a) => Num (InterleavedT m a) where
530 (*) = liftA2 (*)
541 (*) = liftA2 (*)
531 (-) = liftA2 (-)
542 (-) = liftA2 (-)
533−instance (Monad m, Fractional a) => Fractional (InterleavedT m a) where
544+instance (Monad m, Fractional a) => Fractional (CoserialT m a) where
534 fromRational n = pure (fromRational n)
545 fromRational n = pure (fromRational n)
536 recip = fmap recip
547 recip = fmap recip
538 (/) = liftA2 (/)
549 (/) = liftA2 (/)
540−instance (Monad m, Floating a) => Floating (InterleavedT m a) where
551+instance (Monad m, Floating a) => Floating (CoserialT m a) where
541 pi = pure pi
552 pi = pure pi
543 exp = fmap exp
554 exp = fmap exp
@@ -560,7 +571,7 @@ instance (Monad m, Floating a) => Floating (InterleavedT m a) where
560 logBase = liftA2 logBase
571 logBase = liftA2 logBase
562------------------------------------------------------------------------------
573------------------------------------------------------------------------------
563−-- AParallelT
574+-- CoparallelT
564------------------------------------------------------------------------------
575------------------------------------------------------------------------------
566-- | Adaptive parallel, in a left to right 'Semigroup' composition it tries to
577-- | Adaptive parallel, in a left to right 'Semigroup' composition it tries to
@@ -570,7 +581,7 @@ instance (Monad m, Floating a) => Floating (InterleavedT m a) where
570-- enough for the consumer.
581-- enough for the consumer.
573−-- main = ('toList' . 'aparallely' $ (fromFoldable [1,2]) \<> (fromFoldable [3,4])) >>= print
584+-- main = ('toList' . 'coparallely' $ (fromFoldable [1,2]) \<> (fromFoldable [3,4])) >>= print
576-- [1,2,3,4]
587-- [1,2,3,4]
@@ -585,7 +596,7 @@ instance (Monad m, Floating a) => Floating (InterleavedT m a) where
585-- import "Streamly"
596-- import "Streamly"
586-- import Control.Concurrent
597-- import Control.Concurrent
588−-- main = 'runStream' . 'aparallely' $ do
599+-- main = 'runStream' . 'coparallely' $ do
589-- n <- return 3 \<\> return 2 \<\> return 1
600-- n <- return 3 \<\> return 2 \<\> return 1
590-- liftIO $ do
601-- liftIO $ do
591-- threadDelay (n * 1000000)
602-- threadDelay (n * 1000000)
@@ -602,45 +613,45 @@ instance (Monad m, Floating a) => Floating (InterleavedT m a) where
602-- Note that this composition can be used to combine infinite number of streams
613-- Note that this composition can be used to combine infinite number of streams
603-- as it explores only a bounded number of streams at a time.
614-- as it explores only a bounded number of streams at a time.
605−newtype AParallelT m a = AParallelT {getAParallelT :: Stream m a}
616+newtype CoparallelT m a = CoparallelT {getCoparallelT :: Stream m a}
606 deriving (MonadTrans)
617 deriving (MonadTrans)
608−deriving instance MonadAsync m => Monoid (AParallelT m a)
619+deriving instance MonadParallel m => Monoid (CoparallelT m a)
609−deriving instance MonadAsync m => Alternative (AParallelT m)
620+deriving instance MonadParallel m => Alternative (CoparallelT m)
610−deriving instance MonadAsync m => MonadPlus (AParallelT m)
621+deriving instance MonadParallel m => MonadPlus (CoparallelT m)
611−deriving instance MonadAsync m => MonadIO (AParallelT m)
622+deriving instance MonadParallel m => MonadIO (CoparallelT m)
612−deriving instance MonadAsync m => MonadThrow (AParallelT m)
623+deriving instance MonadParallel m => MonadThrow (CoparallelT m)
613−deriving instance (MonadBase b m, MonadAsync m) => MonadBase b (AParallelT m)
624+deriving instance (MonadBase b m, MonadParallel m) => MonadBase b (CoparallelT m)
614−deriving instance (MonadError e m, MonadAsync m) => MonadError e (AParallelT m)
625+deriving instance (MonadError e m, MonadParallel m) => MonadError e (CoparallelT m)
615−deriving instance (MonadReader r m, MonadAsync m) => MonadReader r (AParallelT m)
626+deriving instance (MonadReader r m, MonadParallel m) => MonadReader r (CoparallelT m)
616−deriving instance (MonadState s m, MonadAsync m) => MonadState s (AParallelT m)
627+deriving instance (MonadState s m, MonadParallel m) => MonadState s (CoparallelT m)
618−{-# DEPRECATED AsyncT "Please use 'AParallelT' instead." #-}
629+{-# DEPRECATED AsyncT "Please use 'CoparallelT' instead." #-}
619−type AsyncT = AParallelT
630+type AsyncT = CoparallelT
621−instance IsStream AParallelT where
632+instance IsStream CoparallelT where
622− toStream = getAParallelT
633+ toStream = getCoparallelT
623− fromStream = AParallelT
634+ fromStream = CoparallelT
625------------------------------------------------------------------------------
636------------------------------------------------------------------------------
626-- Semigroup
637-- Semigroup
627------------------------------------------------------------------------------
638------------------------------------------------------------------------------
629−-- | Polymorphic version of the 'Semigroup' operation '<>' of 'AParallelT', but
640+-- | Polymorphic version of the 'Semigroup' operation '<>' of 'CoparallelT', but
630-- polymorphic. Merges two streams possibly concurrently, preferring the
641-- polymorphic. Merges two streams possibly concurrently, preferring the
631-- elements from the left one when available.
642-- elements from the left one when available.
632−{-# INLINE aparallel #-}
643+{-# INLINE coparallel #-}
633−aparallel :: (IsStream t, MonadAsync m) => t m a -> t m a -> t m a
644+coparallel :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
634−aparallel m1 m2 = fromStream $ S.aparallel (toStream m1) (toStream m2)
645+coparallel m1 m2 = fromStream $ S.coparallel (toStream m1) (toStream m2)
636−instance MonadAsync m => Semigroup (AParallelT m a) where
647+instance MonadParallel m => Semigroup (CoparallelT m a) where
637− (<>) = aparallel
648+ (<>) = coparallel
639−-- | Same as 'aparallel'.
650+-- | Same as 'coparallel'.
640−{-# DEPRECATED (<|) "Please use 'aparallel' instead." #-}
651+{-# DEPRECATED (<|) "Please use 'coparallel' instead." #-}
641{-# INLINE (<|) #-}
652{-# INLINE (<|) #-}
642−(<|) :: (IsStream t, MonadAsync m) => t m a -> t m a -> t m a
653+(<|) :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
643−(<|) = aparallel
654+(<|) = coparallel
645------------------------------------------------------------------------------
656------------------------------------------------------------------------------
@@ -661,35 +672,35 @@ parbind par m f = go m
661 yield a (Just r) = run $ f a `par` go r
672 yield a (Just r) = run $ f a `par` go r
662 in g Nothing stp yield
673 in g Nothing stp yield
664−instance MonadAsync m => Monad (AParallelT m) where
675+instance MonadParallel m => Monad (CoparallelT m) where
665 return = pure
676 return = pure
666− (AParallelT m) >>= f = AParallelT $ parbind par m g
677+ (CoparallelT m) >>= f = CoparallelT $ parbind par m g
667− where g x = getAParallelT (f x)
678+ where g x = getCoparallelT (f x)
668 par = S.joinStreamVar2 (SVarStyle Conjunction LIFO)
679 par = S.joinStreamVar2 (SVarStyle Conjunction LIFO)
670------------------------------------------------------------------------------
681------------------------------------------------------------------------------
671-- Applicative
682-- Applicative
672------------------------------------------------------------------------------
683------------------------------------------------------------------------------
674−instance MonadAsync m => Applicative (AParallelT m) where
685+instance MonadParallel m => Applicative (CoparallelT m) where
675− pure a = AParallelT $ S.cons a Nothing
686+ pure a = CoparallelT $ S.cons a Nothing
676 (<*>) = ap
687 (<*>) = ap
678------------------------------------------------------------------------------
689------------------------------------------------------------------------------
679-- Functor
690-- Functor
680------------------------------------------------------------------------------
691------------------------------------------------------------------------------
682−instance Monad m => Functor (AParallelT m) where
693+instance Monad m => Functor (CoparallelT m) where
683− fmap f (AParallelT (Stream m)) = AParallelT $ Stream $ \_ stp yld ->
694+ fmap f (CoparallelT (Stream m)) = CoparallelT $ Stream $ \_ stp yld ->
684 let yield a Nothing = yld (f a) Nothing
695 let yield a Nothing = yld (f a) Nothing
685− yield a (Just r) = yld (f a) (Just (getAParallelT (fmap f (AParallelT r))))
696+ yield a (Just r) = yld (f a) (Just (getCoparallelT (fmap f (CoparallelT r))))
686 in m Nothing stp yield
697 in m Nothing stp yield
688------------------------------------------------------------------------------
699------------------------------------------------------------------------------
690------------------------------------------------------------------------------
701------------------------------------------------------------------------------
692−instance (MonadAsync m, Num a) => Num (AParallelT m a) where
703+instance (MonadParallel m, Num a) => Num (CoparallelT m a) where
693 fromInteger n = pure (fromInteger n)
704 fromInteger n = pure (fromInteger n)
695 negate = fmap negate
706 negate = fmap negate
@@ -700,14 +711,14 @@ instance (MonadAsync m, Num a) => Num (AParallelT m a) where
700 (*) = liftA2 (*)
711 (*) = liftA2 (*)
701 (-) = liftA2 (-)
712 (-) = liftA2 (-)
703−instance (MonadAsync m, Fractional a) => Fractional (AParallelT m a) where
714+instance (MonadParallel m, Fractional a) => Fractional (CoparallelT m a) where
704 fromRational n = pure (fromRational n)
715 fromRational n = pure (fromRational n)
706 recip = fmap recip
717 recip = fmap recip
708 (/) = liftA2 (/)
719 (/) = liftA2 (/)
710−instance (MonadAsync m, Floating a) => Floating (AParallelT m a) where
721+instance (MonadParallel m, Floating a) => Floating (CoparallelT m a) where
711 pi = pure pi
722 pi = pure pi
713 exp = fmap exp
724 exp = fmap exp
@@ -764,7 +775,7 @@ instance (MonadAsync m, Floating a) => Floating (AParallelT m a) where
764-- ThreadId 38: Delay 3
775-- ThreadId 38: Delay 3
767−-- Unlike 'AParallelT' all iterations are guaranteed to run fairly
778+-- Unlike 'CoparallelT' all iterations are guaranteed to run fairly
768-- concurrently, unconditionally.
779-- concurrently, unconditionally.
770-- Note that round robin composition can only combine a finite number of
781-- Note that round robin composition can only combine a finite number of
@@ -773,15 +784,15 @@ instance (MonadAsync m, Floating a) => Floating (AParallelT m a) where
773newtype ParallelT m a = ParallelT {getParallelT :: Stream m a}
784newtype ParallelT m a = ParallelT {getParallelT :: Stream m a}
774 deriving (MonadTrans)
785 deriving (MonadTrans)
776−deriving instance MonadAsync m => Monoid (ParallelT m a)
787+deriving instance MonadParallel m => Monoid (ParallelT m a)
777−deriving instance MonadAsync m => Alternative (ParallelT m)
788+deriving instance MonadParallel m => Alternative (ParallelT m)
778−deriving instance MonadAsync m => MonadPlus (ParallelT m)
789+deriving instance MonadParallel m => MonadPlus (ParallelT m)
779−deriving instance MonadAsync m => MonadIO (ParallelT m)
790+deriving instance MonadParallel m => MonadIO (ParallelT m)
780−deriving instance MonadAsync m => MonadThrow (ParallelT m)
791+deriving instance MonadParallel m => MonadThrow (ParallelT m)
781−deriving instance (MonadBase b m, MonadAsync m) => MonadBase b (ParallelT m)
792+deriving instance (MonadBase b m, MonadParallel m) => MonadBase b (ParallelT m)
782−deriving instance (MonadError e m, MonadAsync m) => MonadError e (ParallelT m)
793+deriving instance (MonadError e m, MonadParallel m) => MonadError e (ParallelT m)
783−deriving instance (MonadReader r m, MonadAsync m) => MonadReader r (ParallelT m)
794+deriving instance (MonadReader r m, MonadParallel m) => MonadReader r (ParallelT m)
784−deriving instance (MonadState s m, MonadAsync m) => MonadState s (ParallelT m)
795+deriving instance (MonadState s m, MonadParallel m) => MonadState s (ParallelT m)
786instance IsStream ParallelT where
797instance IsStream ParallelT where
787 toStream = getParallelT
798 toStream = getParallelT
@@ -794,17 +805,17 @@ instance IsStream ParallelT where
794-- | Polymorphic version of the 'Semigroup' operation '<>' of 'ParallelT'.
805-- | Polymorphic version of the 'Semigroup' operation '<>' of 'ParallelT'.
795-- Merges two streams concurrently choosing elements from both fairly.
806-- Merges two streams concurrently choosing elements from both fairly.
796{-# INLINE parallel #-}
807{-# INLINE parallel #-}
797−parallel :: (IsStream t, MonadAsync m) => t m a -> t m a -> t m a
808+parallel :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
798parallel m1 m2 = fromStream $ S.parallel (toStream m1) (toStream m2)
809parallel m1 m2 = fromStream $ S.parallel (toStream m1) (toStream m2)
800−instance MonadAsync m => Semigroup (ParallelT m a) where
811+instance MonadParallel m => Semigroup (ParallelT m a) where
801 (<>) = parallel
812 (<>) = parallel
803------------------------------------------------------------------------------
814------------------------------------------------------------------------------
805------------------------------------------------------------------------------
816------------------------------------------------------------------------------
807−instance MonadAsync m => Monad (ParallelT m) where
818+instance MonadParallel m => Monad (ParallelT m) where
808 return = pure
819 return = pure
809 (ParallelT m) >>= f = ParallelT $ parbind par m g
820 (ParallelT m) >>= f = ParallelT $ parbind par m g
810 where g x = getParallelT (f x)
821 where g x = getParallelT (f x)
@@ -814,7 +825,7 @@ instance MonadAsync m => Monad (ParallelT m) where
814-- Applicative
825-- Applicative
815------------------------------------------------------------------------------
826------------------------------------------------------------------------------
817−instance MonadAsync m => Applicative (ParallelT m) where
828+instance MonadParallel m => Applicative (ParallelT m) where
818 pure a = ParallelT $ S.cons a Nothing
829 pure a = ParallelT $ S.cons a Nothing
819 (<*>) = ap
830 (<*>) = ap
@@ -833,7 +844,7 @@ instance Monad m => Functor (ParallelT m) where
834------------------------------------------------------------------------------
845------------------------------------------------------------------------------
836−instance (MonadAsync m, Num a) => Num (ParallelT m a) where
847+instance (MonadParallel m, Num a) => Num (ParallelT m a) where
837 fromInteger n = pure (fromInteger n)
848 fromInteger n = pure (fromInteger n)
839 negate = fmap negate
850 negate = fmap negate
@@ -844,14 +855,14 @@ instance (MonadAsync m, Num a) => Num (ParallelT m a) where
844 (*) = liftA2 (*)
855 (*) = liftA2 (*)
845 (-) = liftA2 (-)
856 (-) = liftA2 (-)
847−instance (MonadAsync m, Fractional a) => Fractional (ParallelT m a) where
858+instance (MonadParallel m, Fractional a) => Fractional (ParallelT m a) where
848 fromRational n = pure (fromRational n)
859 fromRational n = pure (fromRational n)
850 recip = fmap recip
861 recip = fmap recip
852 (/) = liftA2 (/)
863 (/) = liftA2 (/)
854−instance (MonadAsync m, Floating a) => Floating (ParallelT m a) where
865+instance (MonadParallel m, Floating a) => Floating (ParallelT m a) where
855 pi = pure pi
866 pi = pure pi
857 exp = fmap exp
868 exp = fmap exp
@@ -892,11 +903,10 @@ zipWith f m1 m2 = fromStream $ go (toStream m1) (toStream m2)
893-- | The applicative instance of 'ZipSerial' zips a number of streams serially
904-- | The applicative instance of 'ZipSerial' zips a number of streams serially
894-- i.e. it produces one element from each stream serially and then zips all
905-- i.e. it produces one element from each stream serially and then zips all
895−-- those elements. Note, for convenience we have used the 'zipping' combinator
906+-- those elements.
896−-- in the following example instead of using a 'ZipSerial' type annotation.
899−-- main = (toList . 'zipping' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
909+-- main = (toList . 'zipSerially' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
900-- where s1 = fromFoldable [1, 2]
910-- where s1 = fromFoldable [1, 2]
901-- s2 = fromFoldable [3, 4]
911-- s2 = fromFoldable [3, 4]
902-- s3 = fromFoldable [5, 6]
912-- s3 = fromFoldable [5, 6]
@@ -915,7 +925,7 @@ newtype ZipSerial m a = ZipSerial {getZipSerial :: Stream m a}
915-- | Same as ZipSerial.
925-- | Same as ZipSerial.
916type ZipStream = ZipSerial
926type ZipStream = ZipSerial
918−deriving instance MonadAsync m => Alternative (ZipSerial m)
928+deriving instance MonadParallel m => Alternative (ZipSerial m)
920instance Monad m => Functor (ZipSerial m) where
930instance Monad m => Functor (ZipSerial m) where
921 fmap f (ZipSerial (Stream m)) = ZipSerial $ Stream $ \_ stp yld ->
931 fmap f (ZipSerial (Stream m)) = ZipSerial $ Stream $ \_ stp yld ->
@@ -976,20 +986,25 @@ instance (Monad m, Floating a) => Floating (ZipSerial m a) where
976-- Parallely Zipping Streams
986-- Parallely Zipping Streams
977------------------------------------------------------------------------------
987------------------------------------------------------------------------------
979−-- | Zip two streams asyncly (i.e. both the elements being zipped are generated
989+-- | Zip two streams concurrently (i.e. both the elements being zipped are
980−-- concurrently) using a pure zipping function.
990+-- generated concurrently) using a pure zipping function.
981−zipAsyncWith :: (IsStream t, MonadAsync m)
991+zipParallelWith :: (IsStream t, MonadParallel m)
982 => (a -> b -> c) -> t m a -> t m b -> t m c
992 => (a -> b -> c) -> t m a -> t m b -> t m c
983−zipAsyncWith f m1 m2 = fromStream $ Stream $ \_ stp yld -> do
993+zipParallelWith f m1 m2 = fromStream $ Stream $ \_ stp yld -> do
984 ma <- async m1
994 ma <- async m1
985 mb <- async m2
995 mb <- async m2
986 (S.runStream (toStream (zipWith f ma mb))) Nothing stp yld
996 (S.runStream (toStream (zipWith f ma mb))) Nothing stp yld
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
988-- | Like 'ZipSerial' but zips in parallel, it generates all the elements to
1003-- | Like 'ZipSerial' but zips in parallel, it generates all the elements to
989-- be zipped concurrently.
1004-- be zipped concurrently.
992−-- main = (toList . 'zippingAsync' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
1007+-- main = (toList . 'zipParallely' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
993-- where s1 = fromFoldable [1, 2]
1008-- where s1 = fromFoldable [1, 2]
994-- s2 = fromFoldable [3, 4]
1009-- s2 = fromFoldable [3, 4]
995-- s3 = fromFoldable [5, 6]
1010-- s3 = fromFoldable [5, 6]
@@ -1001,27 +1016,30 @@ zipAsyncWith f m1 m2 = fromStream $ Stream $ \_ stp yld -> do
1001-- The 'Semigroup' instance of this type works the same way as that of
1016-- The 'Semigroup' instance of this type works the same way as that of
1002-- 'SerialT'.
1017-- 'SerialT'.
1004−newtype ZipAsync m a = ZipAsync {getZipAsync :: Stream m a}
1019+newtype ZipParallel m a = ZipParallel {getZipParallel :: Stream m a}
1005 deriving (Semigroup, Monoid)
1020 deriving (Semigroup, Monoid)
1022+{-# DEPRECATED ZipAsync "Please use ZipParallel instead." #-}
1023+type ZipAsync = ZipParallel
1007−deriving instance MonadAsync m => Alternative (ZipAsync m)
1025+deriving instance MonadParallel m => Alternative (ZipParallel m)
1009−instance Monad m => Functor (ZipAsync m) where
1027+instance Monad m => Functor (ZipParallel m) where
1010− fmap f (ZipAsync (Stream m)) = ZipAsync $ Stream $ \_ stp yld ->
1028+ fmap f (ZipParallel (Stream m)) = ZipParallel $ Stream $ \_ stp yld ->
1011 let yield a Nothing = yld (f a) Nothing
1029 let yield a Nothing = yld (f a) Nothing
1012 yield a (Just r) = yld (f a)
1030 yield a (Just r) = yld (f a)
1013− (Just (getZipAsync (fmap f (ZipAsync r))))
1031+ (Just (getZipParallel (fmap f (ZipParallel r))))
1014 in m Nothing stp yield
1032 in m Nothing stp yield
1016−instance MonadAsync m => Applicative (ZipAsync m) where
1034+instance MonadParallel m => Applicative (ZipParallel m) where
1017− pure = ZipAsync . S.repeat
1035+ pure = ZipParallel . S.repeat
1018− (<*>) = zipAsyncWith id
1036+ (<*>) = zipParallelWith id
1020−instance IsStream ZipAsync where
1038+instance IsStream ZipParallel where
1021− toStream = getZipAsync
1039+ toStream = getZipParallel
1022− fromStream = ZipAsync
1040+ fromStream = ZipParallel
1024−instance (MonadAsync m, Num a) => Num (ZipAsync m a) where
1042+instance (MonadParallel m, Num a) => Num (ZipParallel m a) where
1025 fromInteger n = pure (fromInteger n)
1043 fromInteger n = pure (fromInteger n)
1027 negate = fmap negate
1045 negate = fmap negate
@@ -1032,14 +1050,14 @@ instance (MonadAsync m, Num a) => Num (ZipAsync m a) where
1032 (*) = liftA2 (*)
1050 (*) = liftA2 (*)
1033 (-) = liftA2 (-)
1051 (-) = liftA2 (-)
1035−instance (MonadAsync m, Fractional a) => Fractional (ZipAsync m a) where
1053+instance (MonadParallel m, Fractional a) => Fractional (ZipParallel m a) where
1036 fromRational n = pure (fromRational n)
1054 fromRational n = pure (fromRational n)
1038 recip = fmap recip
1056 recip = fmap recip
1040 (/) = liftA2 (/)
1058 (/) = liftA2 (/)
1042−instance (MonadAsync m, Floating a) => Floating (ZipAsync m a) where
1060+instance (MonadParallel m, Floating a) => Floating (ZipParallel m a) where
1043 pi = pure pi
1061 pi = pure pi
1045 exp = fmap exp
1063 exp = fmap exp
@@ -1073,30 +1091,45 @@ adapt = fromStream . toStream
1073serially :: IsStream t => SerialT m a -> t m a
1091serially :: IsStream t => SerialT m a -> t m a
1074serially = adapt
1092serially = adapt
1076−-- | Fix the type of a polymorphic stream as 'InterleavedT'.
1094+-- | Fix the type of a polymorphic stream as 'CoserialT'.
1077−interleaving :: IsStream t => InterleavedT m a -> t m a
1095+coserially :: IsStream t => CoserialT m a -> t m a
1078−interleaving = adapt
1096+coserially = adapt
1080−-- | Fix the type of a polymorphic stream as 'AParallelT'.
1098+-- | Same as 'coserially'.
1099+{-# DEPRECATED interleaving "Please use coserially instead." #-}
1081−aparallely :: IsStream t => AParallelT m a -> t m a
1100+interleaving :: IsStream t => CoserialT m a -> t m a
1082−aparallely = adapt
1101+interleaving = coserially
1084−-- | Same as 'aparallely'.
1103+-- | Fix the type of a polymorphic stream as 'CoparallelT'.
1104+coparallely :: IsStream t => CoparallelT m a -> t m a
1107+-- | Same as 'coparallely'.
1085−{-# DEPRECATED asyncly "Please use aparallely instead." #-}
1108+{-# DEPRECATED asyncly "Please use coparallely instead." #-}
1086−asyncly :: IsStream t => AParallelT m a -> t m a
1109+asyncly :: IsStream t => CoparallelT m a -> t m a
1087−asyncly = aparallely
1110+asyncly = coparallely
1089-- | Fix the type of a polymorphic stream as 'ParallelT'.
1112-- | Fix the type of a polymorphic stream as 'ParallelT'.
1090parallely :: IsStream t => ParallelT m a -> t m a
1113parallely :: IsStream t => ParallelT m a -> t m a
1091parallely = adapt
1114parallely = adapt
1093-- | Fix the type of a polymorphic stream as 'ZipSerial'.
1116-- | Fix the type of a polymorphic stream as 'ZipSerial'.
1117+zipSerially :: IsStream t => ZipSerial m a -> t m a
1120+-- | Same as 'zipParallely'.
1121+{-# DEPRECATED zipping "Please use zipSerially instead." #-}
1094zipping :: IsStream t => ZipSerial m a -> t m a
1122zipping :: IsStream t => ZipSerial m a -> t m a
1095−zipping = adapt
1123+zipping = zipSerially
1097−-- | Fix the type of a polymorphic stream as 'ZipAsync'.
1125+-- | Fix the type of a polymorphic stream as 'ZipParallel'.
1098−zippingAsync :: IsStream t => ZipAsync m a -> t m a
1126+zipParallely :: IsStream t => ZipParallel m a -> t m a
1099−zippingAsync = adapt
1127+zipParallely = adapt
1129+-- | Same as 'zipParallely'.
1130+{-# DEPRECATED zippingAsync "Please use zipParallely instead." #-}
1131+zippingAsync :: IsStream t => ZipParallel m a -> t m a
1132+zippingAsync = zipParallely
1101-------------------------------------------------------------------------------
1134-------------------------------------------------------------------------------
1102-- Running Streams, convenience functions specialized to types
1135-- Running Streams, convenience functions specialized to types
@@ -1107,15 +1140,15 @@ zippingAsync = adapt
1107runStreamT :: Monad m => SerialT m a -> m ()
1140runStreamT :: Monad m => SerialT m a -> m ()
1108runStreamT = runStream
1141runStreamT = runStream
1110−-- | Same as @runStream . interleaving@.
1143+-- | Same as @runStream . coserially@.
1111{-# DEPRECATED runInterleavedT "Please use 'runStream . interleaving' instead." #-}
1144{-# DEPRECATED runInterleavedT "Please use 'runStream . interleaving' instead." #-}
1112runInterleavedT :: Monad m => InterleavedT m a -> m ()
1145runInterleavedT :: Monad m => InterleavedT m a -> m ()
1113−runInterleavedT = runStream . interleaving
1146+runInterleavedT = runStream . coserially
1115−-- | Same as @runStream . aparallely@.
1148+-- | Same as @runStream . coparallely@.
1116−{-# DEPRECATED runAsyncT "Please use 'runStream . aparallely' instead." #-}
1149+{-# DEPRECATED runAsyncT "Please use 'runStream . coparallely' instead." #-}
1117−runAsyncT :: Monad m => AParallelT m a -> m ()
1150+runAsyncT :: Monad m => CoparallelT m a -> m ()
1118−runAsyncT = runStream . aparallely
1151+runAsyncT = runStream . coparallely
1120-- | Same as @runStream . parallely@.
1153-- | Same as @runStream . parallely@.
1121{-# DEPRECATED runParallelT "Please use 'runStream . parallely' instead." #-}
1154{-# DEPRECATED runParallelT "Please use 'runStream . parallely' instead." #-}
@@ -1123,38 +1156,33 @@ runParallelT :: Monad m => ParallelT m a -> m ()
1123runParallelT = runStream . parallely
1156runParallelT = runStream . parallely
1125-- | Same as @runStream . zipping@.
1158-- | Same as @runStream . zipping@.
1126−{-# DEPRECATED runZipStream "Please use 'runStream . zipping instead." #-}
1159+{-# DEPRECATED runZipStream "Please use 'runStream . zipSerially instead." #-}
1127runZipStream :: Monad m => ZipSerial m a -> m ()
1160runZipStream :: Monad m => ZipSerial m a -> m ()
1128−runZipStream = runStream . zipping
1161+runZipStream = runStream . zipSerially
1130-- | Same as @runStream . zippingAsync@.
1163-- | Same as @runStream . zippingAsync@.
1131−{-# DEPRECATED runZipAsync "Please use 'runStream . zippingAsync instead." #-}
1164+{-# DEPRECATED runZipAsync "Please use 'runStream . zipParallely instead." #-}
1132−runZipAsync :: Monad m => ZipAsync m a -> m ()
1165+runZipAsync :: Monad m => ZipParallel m a -> m ()
1133−runZipAsync = runStream . zippingAsync
1166+runZipAsync = runStream . zipParallely
1135------------------------------------------------------------------------------
1168------------------------------------------------------------------------------
1136-- Fold Utilities
1169-- Fold Utilities
1137------------------------------------------------------------------------------
1170------------------------------------------------------------------------------
1139−-- $foldutils
1172+-- | A variant of 'Data.Foldable.fold' that allows you to fold a 'Foldable'
1140−-- These utilities are designed to pass the first argument as one of the sum
1173+-- container of streams using the specified stream sum operation.
1141−-- style composition operators (i.e. '<>', '<=>', '<|', '<|>') to conveniently
1142−-- fold a container using any style of stream composition.
1144−-- | Like the 'Prelude' 'fold' but allows you to specify a binary sum style
1145−-- stream composition operator to fold a container of streams.
1147−-- @foldWith (<>) $ map return [1..3]@
1175+-- @foldWith 'parallel' $ map return [1..3]@
1148{-# INLINABLE foldWith #-}
1176{-# INLINABLE foldWith #-}
1149foldWith :: (IsStream t, Foldable f)
1177foldWith :: (IsStream t, Foldable f)
1150 => (t m a -> t m a -> t m a) -> f (t m a) -> t m a
1178 => (t m a -> t m a -> t m a) -> f (t m a) -> t m a
1151foldWith f = foldr f nil
1179foldWith f = foldr f nil
1153−-- | Like 'foldMap' but allows you to specify a binary sum style composition
1181+-- | A variant of 'foldMap' that allows you to map a monadic streaming action
1154−-- operator to fold a container of streams. Maps a monadic streaming action on
1182+-- on a 'Foldable' container and then fold it using the specified stream sum
1155−-- the container before folding it.
1183+-- operation.
1157−-- @foldMapWith (<>) return [1..3]@
1185+-- @foldMapWith 'parallel' return [1..3]@
1158{-# INLINABLE foldMapWith #-}
1186{-# INLINABLE foldMapWith #-}
1159foldMapWith :: (IsStream t, Foldable f)
1187foldMapWith :: (IsStream t, Foldable f)
1160 => (t m b -> t m b -> t m b) -> (a -> t m b) -> f a -> t m b
1188 => (t m b -> t m b -> t m b) -> (a -> t m b) -> f a -> t m b