pub fn filter<I, F: Fn(&I) -> bool, E>(f: F) -> Filter<F, E>
Expand description
A parser that accepts only inputs that match the given predicate.
The output type of this parser is I
, the input that was found.
Examples
let lowercase = filter::<_, _, Cheap<char>>(char::is_ascii_lowercase)
.repeated().at_least(1)
.then_ignore(end())
.collect::<String>();
assert_eq!(lowercase.parse("hello"), Ok("hello".to_string()));
assert!(lowercase.parse("Hello").is_err());