@@ -32,6 +32,7 @@ module Streamly.Internal.Data.Stream.Concurrent
3232 , StopWhen (..)
3333 , stopWhen
3434 , ordered
35+ , interleaved
3536 -- maxYields
3637 , Rate(..)
3738 , rate
@@ -62,13 +63,12 @@ module Streamly.Internal.Data.Stream.Concurrent
6263 -- | Use a channel for each pair.
6364 -- combine/concur/conjoin
6465 , append
65− , appendWith
6666 , interleave
67− , interleaveWith
6867 , ahead
6968 , parallel
7069 , parallelFst
7170 , parallelMin
71+ , combineWith
7272
7373 -- ** Apply
7474 -- | Use a separate channel for each application.
@@ -83,7 +83,6 @@ module Streamly.Internal.Data.Stream.Concurrent
8383 , concatMap
8484 , concatMapInterleave
8585 , concatMapWith
86− , concatMapInterleaveWith
8786 )
8887where
8988
@@ -140,23 +139,14 @@ eval = evalWith id
140139-------------------------------------------------------------------------------
141140
142141-- | Like 'append' but with a Config modifier.
143−{-# INLINE appendWith #-}
144−appendWith :: MonadAsync m =>
142+{-# INLINE combineWith #-}
143+combineWith :: MonadAsync m =>
145144 (Config -> Config) -> Stream m a -> Stream m a -> Stream m a
146−appendWith modifier stream1 stream2 =
145+combineWith modifier stream1 stream2 =
147146 Stream.fromStreamK
148147 $ appendWithK
149148 modifier (Stream.toStreamK stream1) (Stream.toStreamK stream2)
150149
151−-- | Like 'interleave' but with a Config modifier.
152−{-# INLINE interleaveWith #-}
153−interleaveWith :: MonadAsync m =>
154− (Config -> Config) -> Stream m a -> Stream m a -> Stream m a
155−interleaveWith modifier stream1 stream2 =
156− Stream.fromStreamK
157− $ interleaveWithK
158− modifier (Stream.toStreamK stream1) (Stream.toStreamK stream2)
159−
160150-- | Binary operation to evaluate two streams concurrently prioritizing the
161151-- left stream.
162152--
@@ -167,7 +157,7 @@ interleaveWith modifier stream1 stream2 =
167157-- all streams. However, with this operation you can precisely control the
168158-- scheduling by creating arbitrary shape expression trees.
169159--
170−-- >>> append = Async.appendWith id
160+-- >>> append = Async.combineWith id
171161--
172162-- The following code finishes in 4 seconds:
173163--
@@ -180,52 +170,52 @@ interleaveWith modifier stream1 stream2 =
180170--
181171{-# INLINE append #-}
182172append :: MonadAsync m => Stream m a -> Stream m a -> Stream m a
183−append = appendWith id
173+append = combineWith id
184174
185175-- | Like 'append' but interleaves the streams fairly instead of prioritizing
186176-- the left stream. This schedules all streams in a round robin fashion over
187177-- limited number of threads.
188178--
189−-- >>> interleave = Async.interleaveWith id
179+-- >>> interleave = Async.combineWith Async.interleaved
190180--
191181{-# INLINE interleave #-}
192182interleave :: MonadAsync m => Stream m a -> Stream m a -> Stream m a
193−interleave = interleaveWith id
183+interleave = combineWith interleaved
194184
195185-- | Like 'append' but with 'ordered' on.
196186--
197−-- >>> ahead = Async.appendWith Async.ordered
187+-- >>> ahead = Async.combineWith Async.ordered
198188--
199189{-# INLINE ahead #-}
200190ahead :: MonadAsync m => Stream m a -> Stream m a -> Stream m a
201−ahead = appendWith ordered
191+ahead = combineWith ordered
202192
203193-- | Like 'append' but with 'eagerEval' on.
204194--
205−-- >>> parallel = Async.appendWith Async.eagerEval
195+-- >>> parallel = Async.combineWith Async.eagerEval
206196--
207197{-# INLINE parallel #-}
208198parallel :: MonadAsync m => Stream m a -> Stream m a -> Stream m a
209−parallel = appendWith eagerEval
199+parallel = combineWith eagerEval
210200
211201-- | Like 'parallel' but stops the output as soon as the first stream stops.
212202--
213−-- >>> parallelFst = Async.appendWith (Async.eagerEval . Async.stopWhen Async.FirstStops)
203+-- >>> parallelFst = Async.combineWith (Async.eagerEval . Async.stopWhen Async.FirstStops)
214204--
215205-- /Pre-release/
216206{-# INLINE parallelFst #-}
217207parallelFst :: MonadAsync m => Stream m a -> Stream m a -> Stream m a
218−parallelFst = appendWith (eagerEval . stopWhen FirstStops)
208+parallelFst = combineWith (eagerEval . stopWhen FirstStops)
219209
220210-- | Like 'parallel' but stops the output as soon as any of the two streams
221211-- stops.
222212--
223−-- >>> parallelMin = Async.appendWith (Async.eagerEval . Async.stopWhen Async.AnyStops)
213+-- >>> parallelMin = Async.combineWith (Async.eagerEval . Async.stopWhen Async.AnyStops)
224214--
225215-- /Pre-release/
226216{-# INLINE parallelMin #-}
227217parallelMin :: MonadAsync m => Stream m a -> Stream m a -> Stream m a
228−parallelMin = appendWith (eagerEval . stopWhen AnyStops)
218+parallelMin = combineWith (eagerEval . stopWhen AnyStops)
229219
230220-- concatMapWith modifier f stream = concatWith modifier $ fmap f stream
231221
@@ -240,17 +230,6 @@ concatMapWith modifier f stream =
240230 $ concatMapWithK
241231 modifier (Stream.toStreamK . f) (Stream.toStreamK stream)
242232
243−-- | Like 'concatMapInterleave' but we can also specify the concurrent
244−-- channel's configuration parameters using Config modifiers.
245−--
246−{-# INLINE concatMapInterleaveWith #-}
247−concatMapInterleaveWith :: MonadAsync m =>
248− (Config -> Config) -> (a -> Stream m b) -> Stream m a -> Stream m b
249−concatMapInterleaveWith modifier f stream =
250− Stream.fromStreamK
251− $ concatMapInterleaveWithK
252− modifier (Stream.toStreamK . f) (Stream.toStreamK stream)
253−
254233-- | Map each element of the input to a stream and then concurrently evaluate
255234-- and concatenate the resulting streams. Multiple streams may be evaluated
256235-- concurrently but earlier streams are perferred. Output from the streams are
@@ -298,11 +277,11 @@ concatMap = concatMapWith id
298277-- evaluate the earlier stream first, this schedules all streams in a round
299278-- robin fashion over the available threads.
300279--
301−-- >>> concatMapInterleave = Async.concatMapInterleaveWith id
280+-- >>> concatMapInterleave = Async.concatMapWith Async.interleaved
302281--
303282-- When used with a single thread it behaves like serial interleaving:
304283--
305−-- >>> f cfg xs = Stream.fold Fold.toList $ Async.concatMapInterleaveWith cfg id $ Stream.fromList xs
284+-- >>> f cfg xs = Stream.fold Fold.toList $ Async.concatMapWith (Async.interleaved . cfg) id $ Stream.fromList xs
306285--
307286-- >>> stream1 = Stream.fromList [1,2,3]
308287-- >>> stream2 = Stream.fromList [4,5,6]
@@ -313,7 +292,7 @@ concatMap = concatMapWith id
313292--
314293{-# INLINE concatMapInterleave #-}
315294concatMapInterleave :: MonadAsync m => (a -> Stream m b) -> Stream m a -> Stream m b
316−concatMapInterleave = concatMapInterleaveWith id
295+concatMapInterleave = concatMapWith interleaved
317296
318297-- | Like 'concat' but we can also specify the concurrent channel's
319298-- configuration parameters using Config modifiers.