sumBy method

int sumBy(
  1. int selector(
    1. T
    )
)

Returns the sum of all values produced by the selector function that is applied to each element.

Example:

[2, 4, 6].sumBy((n) => n);                   // 12
['hello', 'flutter'].sumBy((s) => s.length); // 12

Implementation

int sumBy(int Function(T) selector) {
  ArgumentError.checkNotNull(selector, 'selector');
  return map(selector).fold(0, (prev, curr) => prev + curr);
}