@@ -577,8 +577,8 @@ instance IsStream CoparallelT where
577-- Semigroup
577-- Semigroup
578------------------------------------------------------------------------------
578------------------------------------------------------------------------------
580−-- | Polymorphic version of the 'Semigroup' operation '<>' of 'CoparallelT', but
580+-- | Polymorphic version of the 'Semigroup' operation '<>' of 'CoparallelT'.
581−-- polymorphic. Merges two streams possibly concurrently, preferring the
581+-- Merges two streams possibly concurrently, preferring the
582-- elements from the left one when available.
582-- elements from the left one when available.
583{-# INLINE coparallel #-}
583{-# INLINE coparallel #-}
584coparallel :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
584coparallel :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
@@ -723,16 +723,7 @@ MONAD_COMMON_INSTANCES(ParallelT, MONADPARALLEL)
724-- | Zip two streams serially using a pure zipping function.
724-- | Zip two streams serially using a pure zipping function.
725zipWith :: IsStream t => (a -> b -> c) -> t m a -> t m b -> t m c
725zipWith :: IsStream t => (a -> b -> c) -> t m a -> t m b -> t m c
726−zipWith f m1 m2 = fromStream $ go (toStream m1) (toStream m2)
726+zipWith f m1 m2 = fromStream $ S.zipWith f (toStream m1) (toStream m2)
728− go mx my = S.Stream $ \_ stp sng yld -> do
730− let single2 b = sng (f a b)
731− yield2 b rb = yld (f a b) (go ra rb)
732− in (S.runStream my) Nothing stp single2 yield2
733− let single1 a = merge a S.nil
734− yield1 a ra = merge a ra
735− (S.runStream mx) Nothing stp single1 yield1
737-- | The applicative instance of 'ZipStreamM' zips a number of streams serially
728-- | The applicative instance of 'ZipStreamM' zips a number of streams serially
738-- i.e. it produces one element from each stream serially and then zips all
729-- i.e. it produces one element from each stream serially and then zips all
@@ -754,14 +745,14 @@ zipWith f m1 m2 = fromStream $ go (toStream m1) (toStream m2)
754newtype ZipStreamM m a = ZipStreamM {getZipStreamM :: S.Stream m a}
745newtype ZipStreamM m a = ZipStreamM {getZipStreamM :: S.Stream m a}
755 deriving (Functor, Semigroup, Monoid)
746 deriving (Functor, Semigroup, Monoid)
757−instance Monad m => Applicative (ZipStreamM m) where
758− pure = ZipStreamM . S.repeat
761instance IsStream ZipStreamM where
748instance IsStream ZipStreamM where
762 toStream = getZipStreamM
749 toStream = getZipStreamM
763 fromStream = ZipStreamM
750 fromStream = ZipStreamM
752+instance Monad m => Applicative (ZipStreamM m) where
753+ pure = ZipStreamM . S.repeat
754+ m1 <*> m2 = fromStream $ S.zipWith id (toStream m1) (toStream m2)
765------------------------------------------------------------------------------
756------------------------------------------------------------------------------
766-- Parallely Zipping Streams
757-- Parallely Zipping Streams
767------------------------------------------------------------------------------
758------------------------------------------------------------------------------
@@ -770,10 +761,8 @@ instance IsStream ZipStreamM where
770-- generated concurrently) using a pure zipping function.
761-- generated concurrently) using a pure zipping function.
771zipParallelWith :: (IsStream t, MonadParallel m)
762zipParallelWith :: (IsStream t, MonadParallel m)
772 => (a -> b -> c) -> t m a -> t m b -> t m c
763 => (a -> b -> c) -> t m a -> t m b -> t m c
773−zipParallelWith f m1 m2 = fromStream $ S.Stream $ \_ stp sng yld -> do
764+zipParallelWith f m1 m2 =
774− ma <- async m1
765+ fromStream $ S.zipParallelWith f (toStream m1) (toStream m2)
776− (S.runStream (toStream (zipWith f ma mb))) Nothing stp sng yld
778{-# DEPRECATED zipAsyncWith "Please use zipParallelWith instead." #-}
767{-# DEPRECATED zipAsyncWith "Please use zipParallelWith instead." #-}
779zipAsyncWith :: (IsStream t, MonadParallel m)
768zipAsyncWith :: (IsStream t, MonadParallel m)
@@ -802,14 +791,14 @@ newtype ZipParallelM m a = ZipParallelM {getZipParallelM :: S.Stream m a}
802{-# DEPRECATED ZipAsync "Please use ZipParallelM instead." #-}
791{-# DEPRECATED ZipAsync "Please use ZipParallelM instead." #-}
803type ZipAsync = ZipParallelM
792type ZipAsync = ZipParallelM
805−instance MonadParallel m => Applicative (ZipParallelM m) where
806− pure = ZipParallelM . S.repeat
807− (<*>) = zipParallelWith id
809instance IsStream ZipParallelM where
794instance IsStream ZipParallelM where
810 toStream = getZipParallelM
795 toStream = getZipParallelM
811 fromStream = ZipParallelM
796 fromStream = ZipParallelM
798+instance MonadParallel m => Applicative (ZipParallelM m) where
799+ pure = ZipParallelM . S.repeat
800+ m1 <*> m2 = fromStream $ S.zipParallelWith id (toStream m1) (toStream m2)
813-------------------------------------------------------------------------------
802-------------------------------------------------------------------------------
814-- Type adapting combinators
803-- Type adapting combinators
815-------------------------------------------------------------------------------
804-------------------------------------------------------------------------------