@@ -62,6 +62,11 @@ module Streamly.Internal.Data.Parser
65 -- * Element parsers
70 -- * Element parsers
@@ -202,8 +207,8 @@ module Streamly.Internal.Data.Parser
204import Control.Monad.Catch (MonadCatch, MonadThrow)
209import Control.Monad.Catch (MonadCatch, MonadThrow)
205−import Prelude
210+import Prelude hiding
206− hiding (any, all, take, takeWhile, sequence, concatMap, maybe, either)
211+ (any, all, take, takeWhile, sequence, concatMap, maybe, either, filter)
208import Streamly.Internal.Data.Fold.Type (Fold(..))
213import Streamly.Internal.Data.Fold.Type (Fold(..))
209import Streamly.Internal.Data.Parser.ParserK.Type (Parser)
214import Streamly.Internal.Data.Parser.ParserK.Type (Parser)
@@ -302,6 +307,39 @@ die = D.toParserK . D.die
302dieM :: MonadCatch m => m String -> Parser m a b
307dieM :: MonadCatch m => m String -> Parser m a b
303dieM = D.toParserK . D.dieM
308dieM = D.toParserK . D.dieM
310+-------------------------------------------------------------------------------
312+-------------------------------------------------------------------------------
314+-- | @lmap f parser@ maps the function @f@ on the input of the parser.
316+-- >>> Stream.parse (Parser.lmap (\x -> x * x) (Parser.fromFold Fold.sum)) (Stream.enumerateFromTo 1 100)
319+-- > lmap = Parser.lmapM return
323+lmap :: MonadCatch m => (a -> b) -> Parser m b r -> Parser m a r
324+lmap f p = D.toParserK $ D.lmap f $ D.fromParserK p
326+-- | @lmapM f parser@ maps the monadic function @f@ on the input of the parser.
330+lmapM :: MonadCatch m => (a -> m b) -> Parser m b r -> Parser m a r
331+lmapM f p = D.toParserK $ D.lmapM f $ D.fromParserK p
333+-- | Include only those elements that pass a predicate.
335+-- >>> Stream.parse (Parser.filter (> 5) (Parser.fromFold Fold.sum)) $ Stream.fromList [1..10]
339+{-# INLINE filter #-}
340+filter :: MonadCatch m => (a -> Bool) -> Parser m a b -> Parser m a b
341+filter f p = D.toParserK $ D.filter f $ D.fromParserK p
305-------------------------------------------------------------------------------
343-------------------------------------------------------------------------------
306-- Failing Parsers
344-- Failing Parsers
307-------------------------------------------------------------------------------
345-------------------------------------------------------------------------------