@@ -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 (..)
@@ -65,7 +66,8 @@ module Streamly.Streams
65 , ParallelT
66 , ParallelT
66 , ZipSerial
67 , ZipSerial
67 , ZipStream -- deprecated
68 , ZipStream -- deprecated
68− , ZipAsync
70+ , ZipAsync -- deprecated
70 -- * Type Adapters
72 -- * Type Adapters
71 , serially
73 , serially
@@ -74,8 +76,10 @@ module Streamly.Streams
74 , coparallely
76 , coparallely
75 , asyncly -- deprecated
77 , asyncly -- deprecated
76 , parallely
78 , parallely
77− , zipping
80+ , zipping -- deprecated
78− , zippingAsync
82+ , zippingAsync -- deprecated
81 -- * Running Streams
85 -- * Running Streams
@@ -88,10 +92,10 @@ module Streamly.Streams
89 -- * Zipping
93 -- * Zipping
91− , zipAsyncWith
96+ , zipAsyncWith -- deprecated
93 -- * Fold Utilities
98 -- * Fold Utilities
95 , foldWith
99 , foldWith
96 , foldMapWith
100 , foldMapWith
97 , forEachWith
101 , forEachWith
@@ -109,7 +113,7 @@ import Control.Monad.State.Class (MonadState(..))
109import Control.Monad.Trans.Class (MonadTrans)
113import Control.Monad.Trans.Class (MonadTrans)
110import Data.Semigroup (Semigroup(..))
114import Data.Semigroup (Semigroup(..))
111import Prelude hiding (zipWith)
115import Prelude hiding (zipWith)
112−import Streamly.Core ( MonadAsync, Stream(Stream)
116+import Streamly.Core ( MonadParallel, Stream(Stream)
113 , SVar, SVarStyle(..)
117 , SVar, SVarStyle(..)
114 , SVarTag(..), SVarSched(..))
118 , SVarTag(..), SVarSched(..))
115import qualified Streamly.Core as S
119import qualified Streamly.Core as S
@@ -201,7 +205,7 @@ fromCallback :: IsStream t => (forall r. (a -> m r) -> m r) -> t m a
201fromCallback k = fromStream $ Stream $ \_ _ yld -> k (\a -> yld a Nothing)
205fromCallback k = fromStream $ Stream $ \_ _ yld -> k (\a -> yld a Nothing)
203-- | Read an SVar to get a stream.
207-- | Read an SVar to get a stream.
204−fromSVar :: (MonadAsync m, IsStream t) => SVar m a -> t m a
208+fromSVar :: (MonadParallel m, IsStream t) => SVar m a -> t m a
205fromSVar sv = fromStream $ S.fromStreamVar sv
209fromSVar sv = fromStream $ S.fromStreamVar sv
207------------------------------------------------------------------------------
211------------------------------------------------------------------------------
@@ -218,7 +222,9 @@ streamFold sv step blank m =
218 yield a (Just x) = step a (Just (fromStream x))
222 yield a (Just x) = step a (Just (fromStream x))
219 in (S.runStream (toStream m)) sv blank yield
223 in (S.runStream (toStream m)) sv blank yield
221−-- | 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'@.
222runStream :: Monad m => SerialT m a -> m ()
228runStream :: Monad m => SerialT m a -> m ()
223runStream m = go (toStream m)
229runStream m = go (toStream m)
@@ -235,7 +241,7 @@ runStreaming = runStream . adapt
236-- | 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
237-- be read back from the SVar using 'fromSVar'.
243-- be read back from the SVar using 'fromSVar'.
238−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 ()
239toSVar sv m = S.toStreamVar sv (toStream m)
245toSVar sv m = S.toStreamVar sv (toStream m)
241------------------------------------------------------------------------------
247------------------------------------------------------------------------------
@@ -249,7 +255,7 @@ toSVar sv m = S.toStreamVar sv (toStream m)
249-- 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
250-- will always return 'empty'.
256-- will always return 'empty'.
252−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)
253async m = do
259async m = do
254 sv <- S.newStreamVar1 (SVarStyle Disjunction LIFO) (toStream m)
260 sv <- S.newStreamVar1 (SVarStyle Disjunction LIFO) (toStream m)
255 return $ fromSVar sv
261 return $ fromSVar sv
@@ -311,8 +317,8 @@ async m = do
311newtype SerialT m a = SerialT {getSerialT :: Stream m a}
317newtype SerialT m a = SerialT {getSerialT :: Stream m a}
312 deriving (Semigroup, Monoid, MonadTrans, MonadIO, MonadThrow)
318 deriving (Semigroup, Monoid, MonadTrans, MonadIO, MonadThrow)
314−deriving instance MonadAsync m => Alternative (SerialT m)
320+deriving instance MonadParallel m => Alternative (SerialT m)
315−deriving instance MonadAsync m => MonadPlus (SerialT m)
321+deriving instance MonadParallel m => MonadPlus (SerialT m)
316deriving instance (MonadBase b m, Monad m) => MonadBase b (SerialT m)
322deriving instance (MonadBase b m, Monad m) => MonadBase b (SerialT m)
317deriving instance MonadError e m => MonadError e (SerialT m)
323deriving instance MonadError e m => MonadError e (SerialT m)
318deriving instance MonadReader r m => MonadReader r (SerialT m)
324deriving instance MonadReader r m => MonadReader r (SerialT m)
@@ -454,8 +460,8 @@ instance (Monad m, Floating a) => Floating (SerialT m a) where
454newtype CoserialT m a = CoserialT {getCoserialT :: Stream m a}
460newtype CoserialT m a = CoserialT {getCoserialT :: Stream m a}
455 deriving (Monoid, MonadTrans, MonadIO, MonadThrow)
461 deriving (Monoid, MonadTrans, MonadIO, MonadThrow)
457−deriving instance MonadAsync m => Alternative (CoserialT m)
463+deriving instance MonadParallel m => Alternative (CoserialT m)
458−deriving instance MonadAsync m => MonadPlus (CoserialT m)
464+deriving instance MonadParallel m => MonadPlus (CoserialT m)
459deriving instance (MonadBase b m, Monad m) => MonadBase b (CoserialT m)
465deriving instance (MonadBase b m, Monad m) => MonadBase b (CoserialT m)
460deriving instance MonadError e m => MonadError e (CoserialT m)
466deriving instance MonadError e m => MonadError e (CoserialT m)
461deriving instance MonadReader r m => MonadReader r (CoserialT m)
467deriving instance MonadReader r m => MonadReader r (CoserialT m)
@@ -610,15 +616,15 @@ instance (Monad m, Floating a) => Floating (CoserialT m a) where
610newtype CoparallelT m a = CoparallelT {getCoparallelT :: Stream m a}
616newtype CoparallelT m a = CoparallelT {getCoparallelT :: Stream m a}
611 deriving (MonadTrans)
617 deriving (MonadTrans)
613−deriving instance MonadAsync m => Monoid (CoparallelT m a)
619+deriving instance MonadParallel m => Monoid (CoparallelT m a)
614−deriving instance MonadAsync m => Alternative (CoparallelT m)
620+deriving instance MonadParallel m => Alternative (CoparallelT m)
615−deriving instance MonadAsync m => MonadPlus (CoparallelT m)
621+deriving instance MonadParallel m => MonadPlus (CoparallelT m)
616−deriving instance MonadAsync m => MonadIO (CoparallelT m)
622+deriving instance MonadParallel m => MonadIO (CoparallelT m)
617−deriving instance MonadAsync m => MonadThrow (CoparallelT m)
623+deriving instance MonadParallel m => MonadThrow (CoparallelT m)
618−deriving instance (MonadBase b m, MonadAsync m) => MonadBase b (CoparallelT m)
624+deriving instance (MonadBase b m, MonadParallel m) => MonadBase b (CoparallelT m)
619−deriving instance (MonadError e m, MonadAsync m) => MonadError e (CoparallelT m)
625+deriving instance (MonadError e m, MonadParallel m) => MonadError e (CoparallelT m)
620−deriving instance (MonadReader r m, MonadAsync m) => MonadReader r (CoparallelT m)
626+deriving instance (MonadReader r m, MonadParallel m) => MonadReader r (CoparallelT m)
621−deriving instance (MonadState s m, MonadAsync m) => MonadState s (CoparallelT m)
627+deriving instance (MonadState s m, MonadParallel m) => MonadState s (CoparallelT m)
623{-# DEPRECATED AsyncT "Please use 'CoparallelT' instead." #-}
629{-# DEPRECATED AsyncT "Please use 'CoparallelT' instead." #-}
624type AsyncT = CoparallelT
630type AsyncT = CoparallelT
@@ -635,16 +641,16 @@ instance IsStream CoparallelT where
635-- polymorphic. Merges two streams possibly concurrently, preferring the
641-- polymorphic. Merges two streams possibly concurrently, preferring the
636-- elements from the left one when available.
642-- elements from the left one when available.
637{-# INLINE coparallel #-}
643{-# INLINE coparallel #-}
638−coparallel :: (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
639coparallel m1 m2 = fromStream $ S.coparallel (toStream m1) (toStream m2)
645coparallel m1 m2 = fromStream $ S.coparallel (toStream m1) (toStream m2)
641−instance MonadAsync m => Semigroup (CoparallelT m a) where
647+instance MonadParallel m => Semigroup (CoparallelT m a) where
642 (<>) = coparallel
648 (<>) = coparallel
644-- | Same as 'coparallel'.
650-- | Same as 'coparallel'.
645{-# DEPRECATED (<|) "Please use 'coparallel' instead." #-}
651{-# DEPRECATED (<|) "Please use 'coparallel' instead." #-}
646{-# INLINE (<|) #-}
652{-# INLINE (<|) #-}
647−(<|) :: (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
648(<|) = coparallel
654(<|) = coparallel
650------------------------------------------------------------------------------
656------------------------------------------------------------------------------
@@ -666,7 +672,7 @@ parbind par m f = go m
666 yield a (Just r) = run $ f a `par` go r
672 yield a (Just r) = run $ f a `par` go r
667 in g Nothing stp yield
673 in g Nothing stp yield
669−instance MonadAsync m => Monad (CoparallelT m) where
675+instance MonadParallel m => Monad (CoparallelT m) where
670 return = pure
676 return = pure
671 (CoparallelT m) >>= f = CoparallelT $ parbind par m g
677 (CoparallelT m) >>= f = CoparallelT $ parbind par m g
672 where g x = getCoparallelT (f x)
678 where g x = getCoparallelT (f x)
@@ -676,7 +682,7 @@ instance MonadAsync m => Monad (CoparallelT m) where
676-- Applicative
682-- Applicative
677------------------------------------------------------------------------------
683------------------------------------------------------------------------------
679−instance MonadAsync m => Applicative (CoparallelT m) where
685+instance MonadParallel m => Applicative (CoparallelT m) where
680 pure a = CoparallelT $ S.cons a Nothing
686 pure a = CoparallelT $ S.cons a Nothing
681 (<*>) = ap
687 (<*>) = ap
@@ -694,7 +700,7 @@ instance Monad m => Functor (CoparallelT m) where
695------------------------------------------------------------------------------
701------------------------------------------------------------------------------
697−instance (MonadAsync m, Num a) => Num (CoparallelT m a) where
703+instance (MonadParallel m, Num a) => Num (CoparallelT m a) where
698 fromInteger n = pure (fromInteger n)
704 fromInteger n = pure (fromInteger n)
700 negate = fmap negate
706 negate = fmap negate
@@ -705,14 +711,14 @@ instance (MonadAsync m, Num a) => Num (CoparallelT m a) where
705 (*) = liftA2 (*)
711 (*) = liftA2 (*)
706 (-) = liftA2 (-)
712 (-) = liftA2 (-)
708−instance (MonadAsync m, Fractional a) => Fractional (CoparallelT m a) where
714+instance (MonadParallel m, Fractional a) => Fractional (CoparallelT m a) where
709 fromRational n = pure (fromRational n)
715 fromRational n = pure (fromRational n)
711 recip = fmap recip
717 recip = fmap recip
713 (/) = liftA2 (/)
719 (/) = liftA2 (/)
715−instance (MonadAsync m, Floating a) => Floating (CoparallelT m a) where
721+instance (MonadParallel m, Floating a) => Floating (CoparallelT m a) where
716 pi = pure pi
722 pi = pure pi
718 exp = fmap exp
724 exp = fmap exp
@@ -778,15 +784,15 @@ instance (MonadAsync m, Floating a) => Floating (CoparallelT m a) where
778newtype ParallelT m a = ParallelT {getParallelT :: Stream m a}
784newtype ParallelT m a = ParallelT {getParallelT :: Stream m a}
779 deriving (MonadTrans)
785 deriving (MonadTrans)
781−deriving instance MonadAsync m => Monoid (ParallelT m a)
787+deriving instance MonadParallel m => Monoid (ParallelT m a)
782−deriving instance MonadAsync m => Alternative (ParallelT m)
788+deriving instance MonadParallel m => Alternative (ParallelT m)
783−deriving instance MonadAsync m => MonadPlus (ParallelT m)
789+deriving instance MonadParallel m => MonadPlus (ParallelT m)
784−deriving instance MonadAsync m => MonadIO (ParallelT m)
790+deriving instance MonadParallel m => MonadIO (ParallelT m)
785−deriving instance MonadAsync m => MonadThrow (ParallelT m)
791+deriving instance MonadParallel m => MonadThrow (ParallelT m)
786−deriving instance (MonadBase b m, MonadAsync m) => MonadBase b (ParallelT m)
792+deriving instance (MonadBase b m, MonadParallel m) => MonadBase b (ParallelT m)
787−deriving instance (MonadError e m, MonadAsync m) => MonadError e (ParallelT m)
793+deriving instance (MonadError e m, MonadParallel m) => MonadError e (ParallelT m)
788−deriving instance (MonadReader r m, MonadAsync m) => MonadReader r (ParallelT m)
794+deriving instance (MonadReader r m, MonadParallel m) => MonadReader r (ParallelT m)
789−deriving instance (MonadState s m, MonadAsync m) => MonadState s (ParallelT m)
795+deriving instance (MonadState s m, MonadParallel m) => MonadState s (ParallelT m)
791instance IsStream ParallelT where
797instance IsStream ParallelT where
792 toStream = getParallelT
798 toStream = getParallelT
@@ -799,17 +805,17 @@ instance IsStream ParallelT where
799-- | Polymorphic version of the 'Semigroup' operation '<>' of 'ParallelT'.
805-- | Polymorphic version of the 'Semigroup' operation '<>' of 'ParallelT'.
800-- Merges two streams concurrently choosing elements from both fairly.
806-- Merges two streams concurrently choosing elements from both fairly.
801{-# INLINE parallel #-}
807{-# INLINE parallel #-}
802−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
803parallel m1 m2 = fromStream $ S.parallel (toStream m1) (toStream m2)
809parallel m1 m2 = fromStream $ S.parallel (toStream m1) (toStream m2)
805−instance MonadAsync m => Semigroup (ParallelT m a) where
811+instance MonadParallel m => Semigroup (ParallelT m a) where
806 (<>) = parallel
812 (<>) = parallel
808------------------------------------------------------------------------------
814------------------------------------------------------------------------------
810------------------------------------------------------------------------------
816------------------------------------------------------------------------------
812−instance MonadAsync m => Monad (ParallelT m) where
818+instance MonadParallel m => Monad (ParallelT m) where
813 return = pure
819 return = pure
814 (ParallelT m) >>= f = ParallelT $ parbind par m g
820 (ParallelT m) >>= f = ParallelT $ parbind par m g
815 where g x = getParallelT (f x)
821 where g x = getParallelT (f x)
@@ -819,7 +825,7 @@ instance MonadAsync m => Monad (ParallelT m) where
819-- Applicative
825-- Applicative
820------------------------------------------------------------------------------
826------------------------------------------------------------------------------
822−instance MonadAsync m => Applicative (ParallelT m) where
828+instance MonadParallel m => Applicative (ParallelT m) where
823 pure a = ParallelT $ S.cons a Nothing
829 pure a = ParallelT $ S.cons a Nothing
824 (<*>) = ap
830 (<*>) = ap
@@ -838,7 +844,7 @@ instance Monad m => Functor (ParallelT m) where
839------------------------------------------------------------------------------
845------------------------------------------------------------------------------
841−instance (MonadAsync m, Num a) => Num (ParallelT m a) where
847+instance (MonadParallel m, Num a) => Num (ParallelT m a) where
842 fromInteger n = pure (fromInteger n)
848 fromInteger n = pure (fromInteger n)
844 negate = fmap negate
850 negate = fmap negate
@@ -849,14 +855,14 @@ instance (MonadAsync m, Num a) => Num (ParallelT m a) where
849 (*) = liftA2 (*)
855 (*) = liftA2 (*)
850 (-) = liftA2 (-)
856 (-) = liftA2 (-)
852−instance (MonadAsync m, Fractional a) => Fractional (ParallelT m a) where
858+instance (MonadParallel m, Fractional a) => Fractional (ParallelT m a) where
853 fromRational n = pure (fromRational n)
859 fromRational n = pure (fromRational n)
855 recip = fmap recip
861 recip = fmap recip
857 (/) = liftA2 (/)
863 (/) = liftA2 (/)
859−instance (MonadAsync m, Floating a) => Floating (ParallelT m a) where
865+instance (MonadParallel m, Floating a) => Floating (ParallelT m a) where
860 pi = pure pi
866 pi = pure pi
862 exp = fmap exp
868 exp = fmap exp
@@ -897,11 +903,10 @@ zipWith f m1 m2 = fromStream $ go (toStream m1) (toStream m2)
898-- | The applicative instance of 'ZipSerial' zips a number of streams serially
904-- | The applicative instance of 'ZipSerial' zips a number of streams serially
899-- 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
900−-- those elements. Note, for convenience we have used the 'zipping' combinator
906+-- those elements.
901−-- in the following example instead of using a 'ZipSerial' type annotation.
904−-- main = (toList . 'zipping' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
909+-- main = (toList . 'zipSerially' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
905-- where s1 = fromFoldable [1, 2]
910-- where s1 = fromFoldable [1, 2]
906-- s2 = fromFoldable [3, 4]
911-- s2 = fromFoldable [3, 4]
907-- s3 = fromFoldable [5, 6]
912-- s3 = fromFoldable [5, 6]
@@ -920,7 +925,7 @@ newtype ZipSerial m a = ZipSerial {getZipSerial :: Stream m a}
920-- | Same as ZipSerial.
925-- | Same as ZipSerial.
921type ZipStream = ZipSerial
926type ZipStream = ZipSerial
923−deriving instance MonadAsync m => Alternative (ZipSerial m)
928+deriving instance MonadParallel m => Alternative (ZipSerial m)
925instance Monad m => Functor (ZipSerial m) where
930instance Monad m => Functor (ZipSerial m) where
926 fmap f (ZipSerial (Stream m)) = ZipSerial $ Stream $ \_ stp yld ->
931 fmap f (ZipSerial (Stream m)) = ZipSerial $ Stream $ \_ stp yld ->
@@ -981,20 +986,25 @@ instance (Monad m, Floating a) => Floating (ZipSerial m a) where
981-- Parallely Zipping Streams
986-- Parallely Zipping Streams
982------------------------------------------------------------------------------
987------------------------------------------------------------------------------
984−-- | 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
985−-- concurrently) using a pure zipping function.
990+-- generated concurrently) using a pure zipping function.
986−zipAsyncWith :: (IsStream t, MonadAsync m)
991+zipParallelWith :: (IsStream t, MonadParallel m)
987 => (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
988−zipAsyncWith f m1 m2 = fromStream $ Stream $ \_ stp yld -> do
993+zipParallelWith f m1 m2 = fromStream $ Stream $ \_ stp yld -> do
989 ma <- async m1
994 ma <- async m1
990 mb <- async m2
995 mb <- async m2
991 (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
993-- | 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
994-- be zipped concurrently.
1004-- be zipped concurrently.
997−-- main = (toList . 'zippingAsync' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
1007+-- main = (toList . 'zipParallely' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
998-- where s1 = fromFoldable [1, 2]
1008-- where s1 = fromFoldable [1, 2]
999-- s2 = fromFoldable [3, 4]
1009-- s2 = fromFoldable [3, 4]
1000-- s3 = fromFoldable [5, 6]
1010-- s3 = fromFoldable [5, 6]
@@ -1006,27 +1016,30 @@ zipAsyncWith f m1 m2 = fromStream $ Stream $ \_ stp yld -> do
1006-- 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
1007-- 'SerialT'.
1017-- 'SerialT'.
1009−newtype ZipAsync m a = ZipAsync {getZipAsync :: Stream m a}
1019+newtype ZipParallel m a = ZipParallel {getZipParallel :: Stream m a}
1010 deriving (Semigroup, Monoid)
1020 deriving (Semigroup, Monoid)
1022+{-# DEPRECATED ZipAsync "Please use ZipParallel instead." #-}
1023+type ZipAsync = ZipParallel
1012−deriving instance MonadAsync m => Alternative (ZipAsync m)
1025+deriving instance MonadParallel m => Alternative (ZipParallel m)
1014−instance Monad m => Functor (ZipAsync m) where
1027+instance Monad m => Functor (ZipParallel m) where
1015− fmap f (ZipAsync (Stream m)) = ZipAsync $ Stream $ \_ stp yld ->
1028+ fmap f (ZipParallel (Stream m)) = ZipParallel $ Stream $ \_ stp yld ->
1016 let yield a Nothing = yld (f a) Nothing
1029 let yield a Nothing = yld (f a) Nothing
1017 yield a (Just r) = yld (f a)
1030 yield a (Just r) = yld (f a)
1018− (Just (getZipAsync (fmap f (ZipAsync r))))
1031+ (Just (getZipParallel (fmap f (ZipParallel r))))
1019 in m Nothing stp yield
1032 in m Nothing stp yield
1021−instance MonadAsync m => Applicative (ZipAsync m) where
1034+instance MonadParallel m => Applicative (ZipParallel m) where
1022− pure = ZipAsync . S.repeat
1035+ pure = ZipParallel . S.repeat
1023− (<*>) = zipAsyncWith id
1036+ (<*>) = zipParallelWith id
1025−instance IsStream ZipAsync where
1038+instance IsStream ZipParallel where
1026− toStream = getZipAsync
1039+ toStream = getZipParallel
1027− fromStream = ZipAsync
1040+ fromStream = ZipParallel
1029−instance (MonadAsync m, Num a) => Num (ZipAsync m a) where
1042+instance (MonadParallel m, Num a) => Num (ZipParallel m a) where
1030 fromInteger n = pure (fromInteger n)
1043 fromInteger n = pure (fromInteger n)
1032 negate = fmap negate
1045 negate = fmap negate
@@ -1037,14 +1050,14 @@ instance (MonadAsync m, Num a) => Num (ZipAsync m a) where
1037 (*) = liftA2 (*)
1050 (*) = liftA2 (*)
1038 (-) = liftA2 (-)
1051 (-) = liftA2 (-)
1040−instance (MonadAsync m, Fractional a) => Fractional (ZipAsync m a) where
1053+instance (MonadParallel m, Fractional a) => Fractional (ZipParallel m a) where
1041 fromRational n = pure (fromRational n)
1054 fromRational n = pure (fromRational n)
1043 recip = fmap recip
1056 recip = fmap recip
1045 (/) = liftA2 (/)
1058 (/) = liftA2 (/)
1047−instance (MonadAsync m, Floating a) => Floating (ZipAsync m a) where
1060+instance (MonadParallel m, Floating a) => Floating (ZipParallel m a) where
1048 pi = pure pi
1061 pi = pure pi
1050 exp = fmap exp
1063 exp = fmap exp
@@ -1101,12 +1114,22 @@ parallely :: IsStream t => ParallelT m a -> t m a
1101parallely = adapt
1114parallely = adapt
1103-- | 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." #-}
1104zipping :: IsStream t => ZipSerial m a -> t m a
1122zipping :: IsStream t => ZipSerial m a -> t m a
1105−zipping = adapt
1123+zipping = zipSerially
1125+-- | Fix the type of a polymorphic stream as 'ZipParallel'.
1126+zipParallely :: IsStream t => ZipParallel m a -> t m a
1127+zipParallely = adapt
1107−-- | Fix the type of a polymorphic stream as 'ZipAsync'.
1129+-- | Same as 'zipParallely'.
1130+{-# DEPRECATED zippingAsync "Please use zipParallely instead." #-}
1108−zippingAsync :: IsStream t => ZipAsync m a -> t m a
1131+zippingAsync :: IsStream t => ZipParallel m a -> t m a
1109−zippingAsync = adapt
1132+zippingAsync = zipParallely
1111-------------------------------------------------------------------------------
1134-------------------------------------------------------------------------------
1112-- Running Streams, convenience functions specialized to types
1135-- Running Streams, convenience functions specialized to types
@@ -1133,38 +1156,33 @@ runParallelT :: Monad m => ParallelT m a -> m ()
1133runParallelT = runStream . parallely
1156runParallelT = runStream . parallely
1135-- | Same as @runStream . zipping@.
1158-- | Same as @runStream . zipping@.
1136−{-# DEPRECATED runZipStream "Please use 'runStream . zipping instead." #-}
1159+{-# DEPRECATED runZipStream "Please use 'runStream . zipSerially instead." #-}
1137runZipStream :: Monad m => ZipSerial m a -> m ()
1160runZipStream :: Monad m => ZipSerial m a -> m ()
1138−runZipStream = runStream . zipping
1161+runZipStream = runStream . zipSerially
1140-- | Same as @runStream . zippingAsync@.
1163-- | Same as @runStream . zippingAsync@.
1141−{-# DEPRECATED runZipAsync "Please use 'runStream . zippingAsync instead." #-}
1164+{-# DEPRECATED runZipAsync "Please use 'runStream . zipParallely instead." #-}
1142−runZipAsync :: Monad m => ZipAsync m a -> m ()
1165+runZipAsync :: Monad m => ZipParallel m a -> m ()
1143−runZipAsync = runStream . zippingAsync
1166+runZipAsync = runStream . zipParallely
1145------------------------------------------------------------------------------
1168------------------------------------------------------------------------------
1146-- Fold Utilities
1169-- Fold Utilities
1147------------------------------------------------------------------------------
1170------------------------------------------------------------------------------
1149−-- $foldutils
1172+-- | A variant of 'Data.Foldable.fold' that allows you to fold a 'Foldable'
1150−-- These utilities are designed to pass the first argument as one of the sum
1173+-- container of streams using the specified stream sum operation.
1151−-- style composition operators (i.e. '<>', '<=>', '<|', '<|>') to conveniently
1152−-- fold a container using any style of stream composition.
1154−-- | Like the 'Prelude' 'fold' but allows you to specify a binary sum style
1155−-- stream composition operator to fold a container of streams.
1157−-- @foldWith (<>) $ map return [1..3]@
1175+-- @foldWith 'parallel' $ map return [1..3]@
1158{-# INLINABLE foldWith #-}
1176{-# INLINABLE foldWith #-}
1159foldWith :: (IsStream t, Foldable f)
1177foldWith :: (IsStream t, Foldable f)
1160 => (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
1161foldWith f = foldr f nil
1179foldWith f = foldr f nil
1163−-- | 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
1164−-- 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
1165−-- the container before folding it.
1183+-- operation.
1167−-- @foldMapWith (<>) return [1..3]@
1185+-- @foldMapWith 'parallel' return [1..3]@
1168{-# INLINABLE foldMapWith #-}
1186{-# INLINABLE foldMapWith #-}
1169foldMapWith :: (IsStream t, Foldable f)
1187foldMapWith :: (IsStream t, Foldable f)
1170 => (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