totalBy method

num totalBy(
  1. num? valueSelector(
    1. E
    )
)

Returns the sum of values calculated by valueSelector for each element.

The valueSelector function is applied to each non-null element in the list. If the list is null or empty, returns 0.

Implementation

num totalBy(num? Function(E) valueSelector) {
  if (isEmptyOrNull) return 0;
  num sum = 0;
  for (final element in this!) {
    sum += valueSelector(element) ?? 0;
  }
  return sum;
}