average method

num? average({
  1. num value(
    1. dynamic
    )?,
})

Returns the average of all the values in this iterable, as defined by value.

Returns null if this is empty.

Example:

['a', 'aa', 'aaa'].average((s) => s.length); // 2
[].average(); // null

Implementation

num? average({num Function(dynamic)? value}) {
  value ??= identity;
  if (this.isEmpty) return null;

  return this.sum(value) / this.length;
}