pAnd
fun <I : Any, O1, O2, U : Any> pAnd(first: Parser<I, O1, U>, second: Parser<I, O2, U>): Parser<I, Pair<O1, O2>, U>
Returns a Parser that runs first and then second in sequence, combining their outputs into a Pair.
If either parser fails the combined parser fails immediately, without consuming any input beyond what the failing parser had already consumed.
Behaviour
| Condition | Result |
|---|---|
| first fails | Failure propagated from first |
| first succeeds, second fails | Failure propagated from second |
| Both succeed | Success with Pair(first.value, second.value); index advanced past both |
Type parameters
I — the shared token type consumed by both parsers.
U — the user context type threaded through unchanged.
Example
val digit = pSatisfy<Char, Unit> { it.isDigit() }
val letter = pSatisfy<Char, Unit> { it.isLetter() }
val digitThenLetter = pAnd(digit, letter)
val input = ParserInput.of("1a".toList(), Unit)
val result = digitThenLetter(input) // Success(Pair('1', 'a'), nextIndex=2, ...)Content copied to clipboard
Return
Parameters
first
the parser to run first.
second
the parser to run after first succeeds.