sum method

N sum({
  1. required N ifEmpty,
})

Returns the sum of all values in this iterable. If the iterable is empty, this function returns the specified ifEmpty parameter.

Implementation

N sum({
  required N ifEmpty,
}) =>
    isEmpty ? ifEmpty : reduce((value, element) => (value + element) as N);