HandySwift icon indicating copy to clipboard operation
HandySwift copied to clipboard

Make the `.sum` function more generic

Open Jeehut opened this issue 3 years ago • 0 comments

Problem Statement

Currently only works on Numeric types.

Suggested Solution

Could be made available for all AdditiveArithmetic types:

extension Sequence where Element: AdditiveArithmetic {
  public func sum() -> Element {
    reduce(.zero, +)
  }
}

Also, a predicate could be added like suggested here.

Jeehut avatar May 17 '22 04:05 Jeehut