average method

double average()

Returns the average or null if there are no elements.

Implementation

double average() {
  var count = 0;
  num sum = 0;
  final i = iterator();
  if (!iterator().hasNext()) return double.nan;
  while (i.hasNext()) {
    final next = i.next();
    // nan values are ignored
    if (!next.isNaN) {
      sum += next;
      count++;
    }
  }
  return sum / count;
}