on master help sign in
Add rmapM to Parser
commit3a90efbd8753602777f5c42af5fa4de024f66ab5 authorRanjeet Kumar Ranjan <ranjeetr@composewell.com> dateThu 29 Sep 2022, 11:22 (4 years ago) parent88334a8
2 files changed+13
core/src/Streamly/Data/Parser.hs+3 core/src/Streamly/Internal/Data/Parser.hs+10
core/src/Streamly/Data/Parser.hs+3
@@ -59,6 +59,9 @@ module Streamly.Data.Parser
5959 , lmap
6060 , lmapM
6161
62+ -- * Map on output
63+ , rmapM
64+
6265 -- ** Filtering
6366 , filter
6467
core/src/Streamly/Internal/Data/Parser.hs+10
@@ -68,6 +68,9 @@ module Streamly.Internal.Data.Parser
6868 , lmapM
6969 , filter
7070
71+ -- * Map on output
72+ , rmapM
73+
7174 -- * Element parsers
7275 , peek
7376
@@ -384,6 +387,13 @@ lmap f p = D.toParserK $ D.lmap f $ D.fromParserK p
384387lmapM :: Monad m => (a -> m b) -> Parser m b r -> Parser m a r
385388lmapM f p = D.toParserK $ D.lmapM f $ D.fromParserK p
386389
390+-- | @rmapM f parser@ maps the monadic function @f@ on the output of the parser.
391+--
392+-- /Internal/
393+{-# INLINE rmapM #-}
394+rmapM :: Monad m => (b -> m c) -> Parser m a b -> Parser m a c
395+rmapM f p = D.toParserK $ D.rmapM f $ D.fromParserK p
396+
387397-- | Include only those elements that pass a predicate.
388398--
389399-- >>> Stream.parse (Parser.filter (> 5) (Parser.fromFold Fold.sum)) $ Stream.fromList [1..10]