CountIf method
Returns the number of elements in the enumerable that match a condition.
Iterates over the entire enumerable and applies a condition
function to
it. If the condition
function returns true
, the count is incremented
by one. Once all of the elements in the enumerable have been visited,
CountIf returns the number of elements that matched the condition.
The CountIf function will iterate over every element in the enumerable.
Implementation
int CountIf(Condition<T> condition) {
final iterator = this.iterator;
int count = 0;
while (iterator.moveNext()) {
if (condition(iterator.current)) count++;
}
return count;
}