pMap
Returns a Parser that runs parser and applies transform to the output value if it succeeds.
pMap is the primary way to convert raw parsed tokens into meaningful domain types without altering parse position or error behaviour.
Behaviour
| Condition | Result |
|---|---|
| parser fails | Failure propagated unchanged |
| parser succeeds | Success with transform(value); index and input unchanged |
Type parameters
O — the output type of parser and the input type of transform.
R — the output type of transform and of the returned parser.
U — the user context type threaded through unchanged.
Example
val digit = pSatisfy<Char, Unit> { it.isDigit() }
val digitInt = pMap(digit) { it.digitToInt() }
val input = ParserInput.of("3".toList(), Unit)
val result = digitInt(input) // Success(3, nextIndex=1, ...)Content copied to clipboard
Return
a Parser that produces transform(value) on success.
Parameters
parser
the parser whose success value is transformed.
transform
a function applied to the parsed value on success; should be side-effect-free.