on master help sign in
Fold the Zip.Concurrent module in Zip itself
5d9ce6eHarendra Kumar
src/Streamly/Internal/Data/Stream/Zip.hs+31
@@ -13,6 +13,8 @@
13-- To run examples in this module:
13-- To run examples in this module:
14--
14--
15-- >>> import qualified Streamly.Prelude as Stream
15-- >>> import qualified Streamly.Prelude as Stream
16+-- >>> import qualified Streamly.Internal.Data.Stream as D
17+-- >>> import qualified Streamly.Data.Fold as Fold
16--
18--
17module Streamly.Internal.Data.Stream.Zip
19module Streamly.Internal.Data.Stream.Zip
18 {-# DEPRECATED "Use \"Streamly.Data.Stream.MkType\" instead." #-}
20 {-# DEPRECATED "Use \"Streamly.Data.Stream.MkType\" instead." #-}
@@ -23,6 +25,8 @@ module Streamly.Internal.Data.Stream.Zip
23 , zipWithK
25 , zipWithK
24 , zipWithMK
26 , zipWithMK
25
27
28+ , ZipConcurrent (..)
29+
26 -- * Deprecated
30 -- * Deprecated
27 , ZipStream
31 , ZipStream
28 )
32 )
@@ -50,6 +54,7 @@ import Streamly.Internal.BaseCompat ((#.))
50import Streamly.Internal.Data.Maybe.Strict (Maybe'(..), toMaybe)
54import Streamly.Internal.Data.Maybe.Strict (Maybe'(..), toMaybe)
51import Streamly.Internal.Data.Stream.Serial (SerialT(..))
55import Streamly.Internal.Data.Stream.Serial (SerialT(..))
52import Streamly.Internal.Data.StreamK (Stream)
56import Streamly.Internal.Data.StreamK (Stream)
57+import Streamly.Internal.Data.Stream.Concurrent (MonadAsync, parZipWith)
53
58
54import qualified Streamly.Internal.Data.Stream.Common as P
59import qualified Streamly.Internal.Data.Stream.Common as P
55import qualified Streamly.Internal.Data.StreamK as K
60import qualified Streamly.Internal.Data.StreamK as K
@@ -62,6 +67,8 @@ import Prelude hiding (map, repeat, zipWith)
62
67
63-- $setup
68-- $setup
64-- >>> import qualified Streamly.Prelude as Stream
69-- >>> import qualified Streamly.Prelude as Stream
70+-- >>> import qualified Streamly.Internal.Data.Stream as D
71+-- >>> import qualified Streamly.Data.Fold as Fold
65-- >>> import Control.Concurrent (threadDelay)
72-- >>> import Control.Concurrent (threadDelay)
66-- >>> :{
73-- >>> :{
67-- delay n = do
74-- delay n = do
@@ -136,3 +143,27 @@ instance Monad m => Applicative (ZipSerialM m) where
136
143
137FOLDABLE_INSTANCE(ZipSerialM)
144FOLDABLE_INSTANCE(ZipSerialM)
138TRAVERSABLE_INSTANCE(ZipSerialM)
145TRAVERSABLE_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
372 , Streamly.Internal.Data.Atomics
372 , Streamly.Internal.Data.Atomics
373 , Streamly.Internal.Data.IOFinalizer.Lifted
373 , Streamly.Internal.Data.IOFinalizer.Lifted
374
374
375+ , Streamly.Internal.Data.Stream.Prelude
375 , Streamly.Internal.Data.Unfold.Prelude
376 , Streamly.Internal.Data.Unfold.Prelude
376 , Streamly.Internal.Data.Fold.Prelude
377 , Streamly.Internal.Data.Fold.Prelude
377
378
378− , Streamly.Internal.Data.Stream.Prelude
379− , Streamly.Internal.Data.Stream.Zip.Concurrent
380−
381 -- streamly-unicode (depends on unicode-data)
379 -- streamly-unicode (depends on unicode-data)
382 , Streamly.Internal.Unicode.Utf8
380 , Streamly.Internal.Unicode.Utf8
383 , Streamly.Internal.Unicode.Char
381 , Streamly.Internal.Unicode.Char