any method

bool any(
  1. bool predicate(
    1. T element
    )
)

Checks if any element in the list satisfies the given predicate.

The predicate function determines whether an element satisfies a condition. It should return true if the element satisfies the condition, or false otherwise.

Returns true if at least one element satisfies the predicate, false otherwise.

Example:

List<int> numbers = [1, 2, 3, 4, 5];
bool hasEvenNumber = numbers.any((number) => number % 2 == 0);
print(hasEvenNumber); // Output: true

Implementation

bool any(bool predicate(T element)) {
  if (this.isEmpty) return false;
  for (final element in this) {
    if (predicate(element)) return true;
  }

  return false;
}