countE method

int countE ([Condition<T> condition ])

Returns the number of elements in the enumerable.

Optionally, a condition can be specified. If so, the total count will be the number of elements for which the condition function returned true.

If the condition parameter is omitted and the underlying collection extends or implements EfficientLengthIterable, the countE method will call the length property of the iterable as an O(1) operation. Otherwise, the countE function will iterate over every element in the enumerable.

Implementation

int countE([Condition<T> condition]) {
  if (condition == null) return this.length;
  final iterator = this.iterator;
  if (!iterator.moveNext()) return 0;
  int count = 0;
  do {
    if (condition(iterator.current)) count++;
  } while (iterator.moveNext());
  return count;
}