sum method
T
sum({
- 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);
}