@@ -20,12 +20,7 @@
21module Streamly.Streams.Zip
21module Streamly.Streams.Zip
28− , ZipSerialM
23+ ZipSerialM
29 , ZipSerial
24 , ZipSerial
30 , ZipStream -- deprecated
25 , ZipStream -- deprecated
31 , zipSerially
26 , zipSerially
@@ -53,10 +48,10 @@ import Text.Read (Lexeme(Ident), lexP, parens, prec, readPrec, readListPrec,
53 readListPrecDefault)
48 readListPrecDefault)
54import Prelude hiding (map, repeat, zipWith)
49import Prelude hiding (map, repeat, zipWith)
56−import Streamly.Streams.StreamK (IsStream(..), Stream, mkStream, foldStream)
51+import Streamly.Streams.StreamK (IsStream(..), Stream)
57−import Streamly.Streams.Parallel (mkParallel)
58import Streamly.Streams.Serial (map)
52import Streamly.Streams.Serial (map)
59−import Streamly.Internal.Data.SVar (MonadAsync, adaptState)
53+import Streamly.Internal.Data.SVar (MonadAsync)
54+import Streamly.Internal.Prelude (zipWith, zipAsyncWith)
61import qualified Streamly.Streams.Prelude as P
56import qualified Streamly.Streams.Prelude as P
62import qualified Streamly.Streams.StreamK as K
57import qualified Streamly.Streams.StreamK as K
@@ -136,39 +131,12 @@ instance Monad m => Functor (ZipSerialM m) where
137instance Monad m => Applicative (ZipSerialM m) where
132instance Monad m => Applicative (ZipSerialM m) where
138 pure = ZipSerialM . K.repeat
133 pure = ZipSerialM . K.repeat
134+ {-# INLINE (<*>) #-}
139− (<*>) = K.zipWith id
135+ (<*>) = zipWith id
141FOLDABLE_INSTANCE(ZipSerialM)
137FOLDABLE_INSTANCE(ZipSerialM)
142TRAVERSABLE_INSTANCE(ZipSerialM)
138TRAVERSABLE_INSTANCE(ZipSerialM)
144−------------------------------------------------------------------------------
146−------------------------------------------------------------------------------
148−-- | Like 'zipWith' but zips concurrently i.e. both the streams being zipped
149−-- are generated concurrently.
152−{-# INLINABLE zipAsyncWith #-}
153−zipAsyncWith :: (IsStream t, MonadAsync m)
154− => (a -> b -> c) -> t m a -> t m b -> t m c
155−zipAsyncWith f m1 m2 = mkStream $ \st stp sng yld -> do
156− ma <- mkParallel (adaptState st) m1
157− mb <- mkParallel (adaptState st) m2
158− foldStream st stp sng yld (K.zipWith f ma mb)
160−-- | Like 'zipWithM' but zips concurrently i.e. both the streams being zipped
161−-- are generated concurrently.
164−{-# INLINABLE zipAsyncWithM #-}
165−zipAsyncWithM :: (IsStream t, MonadAsync m)
166− => (a -> b -> m c) -> t m a -> t m b -> t m c
167−zipAsyncWithM f m1 m2 = mkStream $ \st stp sng yld -> do
168− ma <- mkParallel (adaptState st) m1
169− mb <- mkParallel (adaptState st) m2
170− foldStream st stp sng yld (K.zipWithM f ma mb)
172------------------------------------------------------------------------------
140------------------------------------------------------------------------------
173-- Parallely Zipping Streams
141-- Parallely Zipping Streams
174------------------------------------------------------------------------------
142------------------------------------------------------------------------------
@@ -233,4 +201,5 @@ instance Monad m => Functor (ZipAsyncM m) where
234instance MonadAsync m => Applicative (ZipAsyncM m) where
202instance MonadAsync m => Applicative (ZipAsyncM m) where
235 pure = ZipAsyncM . K.repeat
203 pure = ZipAsyncM . K.repeat
204+ {-# INLINE (<*>) #-}
236 m1 <*> m2 = zipAsyncWith id m1 m2
205 m1 <*> m2 = zipAsyncWith id m1 m2