averageBy method
Returns an average value produced by selector
function applied to each element in the collection.
Implementation
double averageBy(num Function(T) selector) {
num sum = 0.0;
var count = 0;
for (final element in iter) {
final value = selector(element);
// nan values are ignored
if (!value.isNaN) {
sum += value;
count++;
}
}
if (count == 0) {
return double.nan;
}
return sum / count;
}