@@ -25,6 +25,7 @@ module Streamly.Internal.Data.Consumer.Type
26 -- Combinators
26 -- Combinators
29 -- Consumers
30 -- Consumers
@@ -32,8 +33,9 @@ module Streamly.Internal.Data.Consumer.Type
36+import Control.Monad ((>=>))
35import Fusion.Plugin.Types (Fuse(..))
37import Fusion.Plugin.Types (Fuse(..))
36−import Streamly.Internal.Data.Fold.Step (Step(..))
38+import Streamly.Internal.Data.Fold.Step (Step(..), mapMStep)
38import Prelude hiding (take)
40import Prelude hiding (take)
@@ -64,6 +66,22 @@ lmapM f (Consumer step inject extract) = Consumer step1 inject extract
65 step1 x a = f a >>= step x
67 step1 x a = f a >>= step x
69+------------------------------------------------------------------------------
70+-- Mapping on the output
71+------------------------------------------------------------------------------
73+-- | Map a monadic function on the output of a fold.
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)
82+ inject1 x = inject x >>= mapMStep f
83+ step1 s a = step s a >>= mapMStep f
67------------------------------------------------------------------------------
85------------------------------------------------------------------------------
68-- Consumers
86-- Consumers
69------------------------------------------------------------------------------
87------------------------------------------------------------------------------