Skip to content

mapTo ​

mapTo combinator maps the parser's result to a constant value.

Usage ​

ts
const Parser = mapTo(
  sequence(integer(), string('+'), integer()),
  5
)

Success

ts
run(Parser).with('2+2')

{
  isOk: true,
  start: 0,
  end: 3,
  pos: 3,
  value: 5
}

Failure

ts
run(Parser).with('2-2')

{
  isOk: false,
  start: 1,
  end: 2,
  pos: 1,
  expected: '+'
}