Skip to content

Commit 47ced07

Browse files
safarelipaf31
authored andcommitted
add mapParserT (#54)
1 parent a1adc35 commit 47ced07

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Text/Parsing/Parser.purs

+9-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import Control.MonadPlus (class Alternative, class MonadZero, class MonadPlus, c
2525
import Data.Either (Either(..))
2626
import Data.Identity (Identity)
2727
import Data.Monoid (class Monoid, mempty)
28-
import Data.Newtype (class Newtype, unwrap)
28+
import Data.Newtype (class Newtype, unwrap, over)
2929
import Data.Tuple (Tuple(..))
3030
import Text.Parsing.Parser.Pos (Position, initialPos)
3131

@@ -69,7 +69,14 @@ runParser :: forall s a. s -> Parser s a -> Either ParseError a
6969
runParser s = unwrap <<< runParserT s
7070

7171
hoistParserT :: forall s m n a. (m ~> n) -> ParserT s m a -> ParserT s n a
72-
hoistParserT f (ParserT m) = ParserT (mapExceptT (mapStateT f) m)
72+
hoistParserT = mapParserT
73+
74+
-- | Change the underlying monad action and data type in a ParserT monad action.
75+
mapParserT :: forall b n s a m.
76+
( m (Tuple (Either ParseError a) (ParseState s))
77+
-> n (Tuple (Either ParseError b) (ParseState s))
78+
) -> ParserT s m a -> ParserT s n b
79+
mapParserT = over ParserT <<< mapExceptT <<< mapStateT
7380

7481
instance lazyParserT :: Lazy (ParserT s m a) where
7582
defer f = ParserT (ExceptT (defer (runExceptT <<< unwrap <<< f)))

0 commit comments

Comments
 (0)