on master help sign in
Add inspectMode and applyWith to the Async module
a3203ffHarendra Kumar
src/Streamly/Internal/Data/Stream/Async.hs+14−1
@@ -35,6 +35,7 @@ module Streamly.Internal.Data.Stream.Async
35 , minRate
35 , minRate
36 , maxRate
36 , maxRate
37 , constRate
37 , constRate
38+ , inspectMode
38
39
39 -- * Combinators
40 -- * Combinators
40 -- | Stream combinators using Async channel
41 -- | Stream combinators using Async channel
@@ -55,6 +56,7 @@ module Streamly.Internal.Data.Stream.Async
55 , interleaveWith
56 , interleaveWith
56
57
57 , apply
58 , apply
59+ , applyWith
58 , concatList
60 , concatList
59 , concat
61 , concat
60 , concatWith
62 , concatWith
@@ -284,10 +286,21 @@ concat = concatWith id
284concatList :: MonadAsync m => [Stream m a] -> Stream m a
286concatList :: MonadAsync m => [Stream m a] -> Stream m a
285concatList = concat . Stream.fromList
287concatList = concat . Stream.fromList
286
288
289+{-# INLINE applyWith #-}
290+{-# SPECIALIZE applyWith ::
291+ (Config -> Config) -> Stream IO (a -> b) -> Stream IO a -> Stream IO b #-}
292+applyWith :: MonadAsync m =>
293+ (Config -> Config) -> Stream m (a -> b) -> Stream m a -> Stream m b
294+applyWith modifier stream1 stream2 =
295+ concatMapWith
296+ modifier
297+ (\g -> concatMapWith modifier (pure . g) stream2)
298+ stream1
299+
287{-# INLINE apply #-}
300{-# INLINE apply #-}
288{-# SPECIALIZE apply :: Stream IO (a -> b) -> Stream IO a -> Stream IO b #-}
301{-# SPECIALIZE apply :: Stream IO (a -> b) -> Stream IO a -> Stream IO b #-}
289apply :: MonadAsync m => Stream m (a -> b) -> Stream m a -> Stream m b
302apply :: MonadAsync m => Stream m (a -> b) -> Stream m a -> Stream m b
290−apply stream1 stream2 = concatMap (\g -> concatMap (pure . g) stream2) stream1
303+apply = applyWith id
291
304
292-- |
305-- |
293-- >>> mapMWith modifier f = Async.concatMapWith modifier (Stream.fromEffect . f)
306-- >>> mapMWith modifier f = Async.concatMapWith modifier (Stream.fromEffect . f)
src/Streamly/Internal/Data/Stream/Async/Channel.hs+1
@@ -21,6 +21,7 @@ module Streamly.Internal.Data.Stream.Async.Channel
21 , minRate
21 , minRate
22 , maxRate
22 , maxRate
23 , constRate
23 , constRate
24+ , inspectMode
24
25
25 -- * Operations
26 -- * Operations
26 , fromChannel
27 , fromChannel