any method
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;
}