count_ method

int count_({
  1. Expr? where,
})

Returns the number of elements in the source. If where is provided, only elements matching the predicate are counted.

Implementation

int count_({Expr? where}) {
  if (where == null) {
    var n = 0;
    for (final _ in this) {
      n++;
    }
    return n;
  }
  final lambda = _requireSelector('count_', where);
  final paramName = lambda.params.first.name;
  final body = lambda.body;
  var n = 0;
  for (final e in this) {
    if (body.eval({paramName: e}) == true) n++;
  }
  return n;
}