Add rmapM to Parser

This commit is contained in:
Ranjeet Kumar Ranjan 2022-09-29 11:22:31 +05:30 committed by Harendra Kumar
parent 88334a8190
commit 3a90efbd87
2 changed files with 13 additions and 0 deletions

View File

@ -59,6 +59,9 @@ module Streamly.Data.Parser
, lmap
, lmapM
-- * Map on output
, rmapM
-- ** Filtering
, filter

View File

@ -68,6 +68,9 @@ module Streamly.Internal.Data.Parser
, lmapM
, filter
-- * Map on output
, rmapM
-- * Element parsers
, peek
@ -384,6 +387,13 @@ lmap f p = D.toParserK $ D.lmap f $ D.fromParserK p
lmapM :: Monad m => (a -> m b) -> Parser m b r -> Parser m a r
lmapM f p = D.toParserK $ D.lmapM f $ D.fromParserK p
-- | @rmapM f parser@ maps the monadic function @f@ on the output of the parser.
--
-- /Internal/
{-# INLINE rmapM #-}
rmapM :: Monad m => (b -> m c) -> Parser m a b -> Parser m a c
rmapM f p = D.toParserK $ D.rmapM f $ D.fromParserK p
-- | Include only those elements that pass a predicate.
--
-- >>> Stream.parse (Parser.filter (> 5) (Parser.fromFold Fold.sum)) $ Stream.fromList [1..10]