map<S> method
Returns a parser that evaluates a callback
as the production action
on success of the receiver.
callback
should be side-effect free, meaning for the same input it
always gives the same output. This allows the framework skip calling
the callback if the result is not used, or to cache the results. If
callback
has side-effects, make sure to exactly understand the
implications and set hasSideEffects
to true
.
For example, the parser digit().map((char) => int.parse(char))
returns
the number 1
for the input string '1'
. If the delegate fails, the
production action is not executed and the failure is passed on.
Implementation
@useResult
Parser<S> map<S>(Callback<R, S> callback, {bool hasSideEffects = false}) =>
MapParser<R, S>(this, callback, hasSideEffects: hasSideEffects);