meanByIndexed<T> function
Returns the arithmetic mean of numeric values extracted from values using
indexed valueof.
Implementation
double? meanByIndexed<T>(
Iterable<T> values,
num? Function(T value, int index, Iterable<T> values) valueof,
) {
var count = 0;
var sum = 0.0;
var index = -1;
for (final value in values) {
final raw = valueof(value, ++index, values);
if (raw != null) {
final v = raw.toDouble();
if (v >= v) {
++count;
sum += v;
}
}
}
return count > 0 ? sum / count : null;
}