on master help sign in
Add distributeAsync_
83acf91Harendra Kumar
src/Streamly/Internal/Data/Stream/Parallel.hs+26−1
@@ -21,16 +21,25 @@
21--
21--
22module Streamly.Internal.Data.Stream.Parallel
22module Streamly.Internal.Data.Stream.Parallel
23 (
23 (
24+ -- * Parallel Stream Type
24 ParallelT
25 ParallelT
25 , Parallel
26 , Parallel
26 , parallely
27 , parallely
28+
29+ -- * Merge Concurrently
27 , parallel
30 , parallel
28 , parallelFst
31 , parallelFst
29 , parallelMin
32 , parallelMin
30− , tapAsync
33+
34+ -- * Evaluate Concurrently
31 , mkParallel
35 , mkParallel
32 , applyParallel
36 , applyParallel
33 , foldParallel
37 , foldParallel
38+
39+ -- * Tap Concurrently
40+ , tapAsync
41+ , distributeAsync_
42+
34 )
43 )
35where
44where
36
45
@@ -386,6 +395,22 @@ tapAsync f m = mkStream $ \st yld sng stp -> do
386 sv <- newFoldSVar st f
395 sv <- newFoldSVar st f
387 foldStreamShared st yld sng stp (teeToSVar sv m)
396 foldStreamShared st yld sng stp (teeToSVar sv m)
388
397
398+-- | Concurrently distribute a stream to a collection of fold functions,
399+-- discarding the outputs of the folds.
400+--
401+-- >>> S.drain $ distributeAsync_ [S.mapM_ print, S.mapM_ print] (S.enumerateFromTo 1 2)
402+--
403+-- @
404+-- distributeAsync_ = flip (foldr tapAsync)
405+-- @
406+--
407+-- /Internal/
408+--
409+{-# INLINE distributeAsync_ #-}
410+distributeAsync_ :: (Foldable f, IsStream t, MonadAsync m)
411+ => f (t m a -> m b) -> t m a -> t m a
412+distributeAsync_ = flip (foldr tapAsync)
413+
389------------------------------------------------------------------------------
414------------------------------------------------------------------------------
390-- ParallelT
415-- ParallelT
391------------------------------------------------------------------------------
416------------------------------------------------------------------------------