matches method

  1. @override
bool matches(
  1. T other
)
override

Whether this filter matches the given other instance.

Evaluates filter criteria against field values extracted from other using the field's value getter function.

final filter = Filter.and([
  Filter.equal(UserField.name, 'John'),
  Filter.greater(UserField.age, 18),
]);

final user1 = User('1', 'John', 25);
print(filter.matches(user1)); // true

final user2 = User('2', 'Jane', 25);
print(filter.matches(user2)); // false

Implementation

@override
bool matches(T other) {
  final fieldValue = field.value(other);
  final valueExists = fieldValue != null;

  return exists ? valueExists : !valueExists;
}