@@ -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------------------------------------------------------------------------------