Returns the average of a list, after mapping each element to a number using the provided function.

Use to map each element to the numeric value returned by fn, Iterable.reduce() to sum the values, divide by Iterable.length to get the average.


num averageBy<T>(List<T> lst, num Function(T) fn) {
  return a, num b) => a + b) / lst.length;


averageBy([ {'n': 4}, {'n': 2}, {'n': 8}, {'n': 6} ], (o) => o['n']); // 5