on master help sign in
Fold the Zip.Concurrent module in Zip itself
commit5d9ce6e348e6bd1449a172da85509cca19f41bad authorHarendra Kumar <harendra@composewell.com> dateMon 27 Nov 2023, 05:14 (3 years ago) parentfd93674
3 files changed+32−54
src/Streamly/Internal/Data/Stream/Zip.hs+31 src/Streamly/Internal/Data/Stream/Zip/Concurrent.hs−51 streamly.cabal+1−3
src/Streamly/Internal/Data/Stream/Zip.hs+31
@@ -13,6 +13,8 @@
1313-- To run examples in this module:
1414--
1515-- >>> import qualified Streamly.Prelude as Stream
16+-- >>> import qualified Streamly.Internal.Data.Stream as D
17+-- >>> import qualified Streamly.Data.Fold as Fold
1618--
1719module Streamly.Internal.Data.Stream.Zip
1820 {-# DEPRECATED "Use \"Streamly.Data.Stream.MkType\" instead." #-}
@@ -23,6 +25,8 @@ module Streamly.Internal.Data.Stream.Zip
2325 , zipWithK
2426 , zipWithMK
2527
28+ , ZipConcurrent (..)
29+
2630 -- * Deprecated
2731 , ZipStream
2832 )
@@ -50,6 +54,7 @@ import Streamly.Internal.BaseCompat ((#.))
5054import Streamly.Internal.Data.Maybe.Strict (Maybe'(..), toMaybe)
5155import Streamly.Internal.Data.Stream.Serial (SerialT(..))
5256import Streamly.Internal.Data.StreamK (Stream)
57+import Streamly.Internal.Data.Stream.Concurrent (MonadAsync, parZipWith)
5358
5459import qualified Streamly.Internal.Data.Stream.Common as P
5560import qualified Streamly.Internal.Data.StreamK as K
@@ -62,6 +67,8 @@ import Prelude hiding (map, repeat, zipWith)
6267
6368-- $setup
6469-- >>> import qualified Streamly.Prelude as Stream
70+-- >>> import qualified Streamly.Internal.Data.Stream as D
71+-- >>> import qualified Streamly.Data.Fold as Fold
6572-- >>> import Control.Concurrent (threadDelay)
6673-- >>> :{
6774-- delay n = do
@@ -136,3 +143,27 @@ instance Monad m => Applicative (ZipSerialM m) where
136143
137144FOLDABLE_INSTANCE(ZipSerialM)
138145TRAVERSABLE_INSTANCE(ZipSerialM)
146+
147+-------------------------------------------------------------------------------
148+-- ZipConcurrent
149+-------------------------------------------------------------------------------
150+
151+newtype ZipConcurrent m a = ZipConcurrent {getZipConcurrent :: D.Stream m a}
152+ deriving (Functor)
153+
154+-- | An IO stream whose applicative instance zips streams concurrently. Note
155+-- that it uses the default concurrency options.
156+--
157+-- >>> s = ZipConcurrent $ D.fromList [1, 2, 3]
158+-- >>> x = (,,) <$> s <*> s <*> s
159+-- >>> D.fold Fold.toList (getZipConcurrent x)
160+-- [(1,1,1),(2,2,2),(3,3,3)]
161+--
162+-- @since 0.9.0
163+
164+instance MonadAsync m => Applicative (ZipConcurrent m) where
165+ pure = ZipConcurrent . D.repeat
166+
167+ {-# INLINE (<*>) #-}
168+ ZipConcurrent m1 <*> ZipConcurrent m2 =
169+ ZipConcurrent $ parZipWith id id m1 m2
src/Streamly/Internal/Data/Stream/Zip/Concurrent.hsdeleted−51
@@ -1,51 +0,0 @@
1−{-# LANGUAGE UndecidableInstances #-}
2−-- |
3−-- Module : Streamly.Internal.Data.Stream.Concurrent
4−-- Copyright : (c) 2017 Composewell Technologies
5−-- License : BSD-3-Clause
6−-- Maintainer : streamly@composewell.com
7−-- Stability : experimental
8−-- Portability : GHC
9−--
10−-- To run examples in this module:
11−--
12−-- >>> import qualified Streamly.Internal.Data.Stream as Stream
13−-- >>> import qualified Streamly.Data.Fold as Fold
14−--
15−module Streamly.Internal.Data.Stream.Zip.Concurrent
16− {-# DEPRECATED "Use \"Streamly.Data.Stream.MkType\" instead." #-}
17− (
18− ZipConcurrent (..)
19− )
20−where
21−
22−import Streamly.Internal.Data.Stream (Stream)
23−import Streamly.Internal.Data.Stream.Concurrent (MonadAsync, parZipWith)
24−
25−import qualified Streamly.Internal.Data.Stream as Stream (repeat)
26−import Prelude hiding (map, repeat, zipWith)
27−
28−-- $setup
29−-- >>> import qualified Streamly.Internal.Data.Stream as Stream
30−-- >>> import qualified Streamly.Data.Fold as Fold
31−--
32−
33−newtype ZipConcurrent m a = ZipConcurrent {getZipConcurrent :: Stream m a}
34− deriving (Functor)
35−
36−-- | An IO stream whose applicative instance zips streams concurrently. Note
37−-- that it uses the default concurrency options.
38−--
39−-- >>> s = ZipConcurrent $ Stream.fromList [1, 2, 3]
40−-- >>> x = (,,) <$> s <*> s <*> s
41−-- >>> Stream.fold Fold.toList (getZipConcurrent x)
42−-- [(1,1,1),(2,2,2),(3,3,3)]
43−--
44−-- @since 0.9.0
45−
46−instance MonadAsync m => Applicative (ZipConcurrent m) where
47− pure = ZipConcurrent . Stream.repeat
48−
49− {-# INLINE (<*>) #-}
50− ZipConcurrent m1 <*> ZipConcurrent m2 =
51− ZipConcurrent $ parZipWith id id m1 m2
streamly.cabal+1−3
@@ -372,12 +372,10 @@ library
372372 , Streamly.Internal.Data.Atomics
373373 , Streamly.Internal.Data.IOFinalizer.Lifted
374374
375+ , Streamly.Internal.Data.Stream.Prelude
375376 , Streamly.Internal.Data.Unfold.Prelude
376377 , Streamly.Internal.Data.Fold.Prelude
377378
378− , Streamly.Internal.Data.Stream.Prelude
379− , Streamly.Internal.Data.Stream.Zip.Concurrent
380−
381379 -- streamly-unicode (depends on unicode-data)
382380 , Streamly.Internal.Unicode.Utf8
383381 , Streamly.Internal.Unicode.Char