average method
Returns the average of all the values in this iterable.
If value
is provided, it will be used to compute the value to be
averaged.
Returns null if this
is empty.
Example:
[2, 2, 4, 8].average(); // 4.
[2, 2, 4, 8].average((i) => i + 1); // 5.
[].average() // null.
Implementation
num? average([num Function(E)? value]) {
if (this.isEmpty) return null;
return this.sum(value) / this.length;
}