on master help sign in
Add rmapM to Parser
3a90efbRanjeet Kumar Ranjan
core/src/Streamly/Data/Parser.hs+3
@@ -59,6 +59,9 @@ module Streamly.Data.Parser
59 , lmap
59 , lmap
60 , lmapM
60 , lmapM
61
61
62+ -- * Map on output
63+ , rmapM
64+
62 -- ** Filtering
65 -- ** Filtering
63 , filter
66 , filter
64
67
core/src/Streamly/Internal/Data/Parser.hs+10
@@ -68,6 +68,9 @@ module Streamly.Internal.Data.Parser
68 , lmapM
68 , lmapM
69 , filter
69 , filter
70
70
71+ -- * Map on output
72+ , rmapM
73+
71 -- * Element parsers
74 -- * Element parsers
72 , peek
75 , peek
73
76
@@ -384,6 +387,13 @@ lmap f p = D.toParserK $ D.lmap f $ D.fromParserK p
384lmapM :: Monad m => (a -> m b) -> Parser m b r -> Parser m a r
387lmapM :: Monad m => (a -> m b) -> Parser m b r -> Parser m a r
385lmapM f p = D.toParserK $ D.lmapM f $ D.fromParserK p
388lmapM f p = D.toParserK $ D.lmapM f $ D.fromParserK p
386
389
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+
387-- | Include only those elements that pass a predicate.
397-- | Include only those elements that pass a predicate.
388--
398--
389-- >>> Stream.parse (Parser.filter (> 5) (Parser.fromFold Fold.sum)) $ Stream.fromList [1..10]
399-- >>> Stream.parse (Parser.filter (> 5) (Parser.fromFold Fold.sum)) $ Stream.fromList [1..10]