count method

int count([
  1. bool predicate(
    1. E element
    )?
])

Returns the number of elements matching the given predicate.

If no predicate is given, this equals to length.

Implementation

int count([bool Function(E element)? predicate]) {
  var count = 0;
  if (predicate == null) {
    return length;
  } else {
    for (var current in this) {
      if (predicate(current)) {
        count++;
      }
    }
  }

  return count;
}