@@ -20,12 +20,7 @@
2020--
2121module Streamly.Streams.Zip
2222 (
23− K.zipWith
24− , K.zipWithM
25− , zipAsyncWith
26− , zipAsyncWithM
27−
28− , ZipSerialM
23+ ZipSerialM
2924 , ZipSerial
3025 , ZipStream -- deprecated
3126 , zipSerially
@@ -53,10 +48,10 @@ import Text.Read (Lexeme(Ident), lexP, parens, prec, readPrec, readListPrec,
5348 readListPrecDefault)
5449import Prelude hiding (map, repeat, zipWith)
5550
56−import Streamly.Streams.StreamK (IsStream(..), Stream, mkStream, foldStream)
57−import Streamly.Streams.Parallel (mkParallel)
51+import Streamly.Streams.StreamK (IsStream(..), Stream)
5852import 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)
6055
6156import qualified Streamly.Streams.Prelude as P
6257import qualified Streamly.Streams.StreamK as K
@@ -136,39 +131,12 @@ instance Monad m => Functor (ZipSerialM m) where
136131
137132instance Monad m => Applicative (ZipSerialM m) where
138133 pure = ZipSerialM . K.repeat
139− (<*>) = K.zipWith id
134+ {-# INLINE (<*>) #-}
135+ (<*>) = zipWith id
140136
141137FOLDABLE_INSTANCE(ZipSerialM)
142138TRAVERSABLE_INSTANCE(ZipSerialM)
143139
144−------------------------------------------------------------------------------
145−-- Parallel Zipping
146−------------------------------------------------------------------------------
147−
148−-- | Like 'zipWith' but zips concurrently i.e. both the streams being zipped
149−-- are generated concurrently.
150−--
151−-- @since 0.1.0
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)
159−
160−-- | Like 'zipWithM' but zips concurrently i.e. both the streams being zipped
161−-- are generated concurrently.
162−--
163−-- @since 0.4.0
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)
171−
172140------------------------------------------------------------------------------
173141-- Parallely Zipping Streams
174142------------------------------------------------------------------------------
@@ -233,4 +201,5 @@ instance Monad m => Functor (ZipAsyncM m) where
233201
234202instance MonadAsync m => Applicative (ZipAsyncM m) where
235203 pure = ZipAsyncM . K.repeat
204+ {-# INLINE (<*>) #-}
236205 m1 <*> m2 = zipAsyncWith id m1 m2