on master help sign in
Add rmapM to Consumer module
commit2d9654f229c1f1a3eb7dade21dea7b89b4d2a06c authorHarendra Kumar <harendra@composewell.com> dateSat 9 Oct 2021, 17:07 (5 years ago) parent0548e36
1 file changed+19−1
src/Streamly/Internal/Data/Consumer/Type.hs+19−1
src/Streamly/Internal/Data/Consumer/Type.hs+19−1
@@ -25,6 +25,7 @@ module Streamly.Internal.Data.Consumer.Type
2525
2626 -- Combinators
2727 , lmapM
28+ , rmapM
2829
2930 -- Consumers
3031 , drainBy
@@ -32,8 +33,9 @@ module Streamly.Internal.Data.Consumer.Type
3233 )
3334where
3435
36+import Control.Monad ((>=>))
3537import Fusion.Plugin.Types (Fuse(..))
36−import Streamly.Internal.Data.Fold.Step (Step(..))
38+import Streamly.Internal.Data.Fold.Step (Step(..), mapMStep)
3739
3840import Prelude hiding (take)
3941
@@ -64,6 +66,22 @@ lmapM f (Consumer step inject extract) = Consumer step1 inject extract
6466
6567 step1 x a = f a >>= step x
6668
69+------------------------------------------------------------------------------
70+-- Mapping on the output
71+------------------------------------------------------------------------------
72+
73+-- | Map a monadic function on the output of a fold.
74+--
75+-- /Internal/
76+{-# INLINE rmapM #-}
77+rmapM :: Monad m => (b -> m c) -> Consumer m x a b -> Consumer m x a c
78+rmapM f (Consumer step inject extract) = Consumer step1 inject1 (extract >=> f)
79+
80+ where
81+
82+ inject1 x = inject x >>= mapMStep f
83+ step1 s a = step s a >>= mapMStep f
84+
6785------------------------------------------------------------------------------
6886-- Consumers
6987------------------------------------------------------------------------------