predicate<T> function

Matcher predicate<T>(
  1. bool f(
    1. T
  2. [String description = 'satisfies function']

Returns a matcher that uses an arbitrary function that returns whether the value is considered a match.

For example:

expect(actual, predicate<num>((v) => (v % 2) == 0, 'is even'));

Use this method when a value is checked for one conceptual property described by description.

If the value can be rejected for more than one reason prefer using isA and the TypeMatcher.having API to build up a matcher with output that can distinquish between them.

Using an explicit generict argument allows a passed function literal to have an inferred argument type of T, and values of the wrong type will be rejected with an informative message.


Matcher predicate<T>(bool Function(T) f,
        [String description = 'satisfies function']) =>
    _Predicate(f, description);