sum method

num sum([
  1. num addend(
    1. dynamic
    )?
])

Returns the sum of all the values in this iterable, as defined by addend.

Returns 0 if this is empty.

Example:

['a', 'aa', 'aaa'].sum((s) => s.length); // 6

Implementation

num sum([num Function(dynamic)? addend]) {
  addend ??= identity;
  return this.isEmpty
      ? 0
      : this.fold(0, (prev, element) => prev + addend!(element));
}