sum method

T sum({
  1. T? identity,
})

Sum of all elements. Returns identity (default 0) if empty.

Implementation

T sum({T? identity}) {
  if (isEmpty) return (identity ?? 0) as T;
  return reduce((a, b) => (a + b) as T);
}