where method
- @useResult
- Predicate<
R> predicate, { - String? message,
- FailureFactory<
R> ? factory,
Returns a parser that evaluates the predicate with the successful
parse result.
If the predicate returns true the parser proceeds with the parse result,
otherwise a parse failure is created using the optionally specified
factory callback, the provided message, or otherwise an automatically
created error message.
The following example parses two characters, but only succeeds if they are equal:
final inner = any() & any();
final parser = inner.where(
(value) => value[0] == value[1],
factory: (context, success) =>
context.failure('characters do not match'));
parser.parse('aa'); // ==> Success: ['a', 'a']
parser.parse('ab'); // ==> Failure: characters do not match
Implementation
@useResult
Parser<R> where(
Predicate<R> predicate, {
String? message,
FailureFactory<R>? factory,
}) => WhereParser<R>(this, predicate, factory ?? defaultFactory_(message));