mean function

double? mean(
  1. Iterable<num> iterable
)

Returns the arithmetic mean of the given iterable. Returns null if the iterable is empty.

Implementation

double? mean(Iterable<num> iterable) {
  final iterator = iterable.iterator;
  if (!iterator.moveNext()) return null;

  num total = iterator.current;
  int count = 1;

  while (iterator.moveNext()) {
    total += iterator.current;
    count++;
  }

  return total / count;
}