available when Element conforms to AdditiveArithmetic.
๐พ ็จๅผ๏ผ paiza.io
// ๐ ฟ๏ธ `AdditiveArithmetic`: supports +, -, .zero. extension Sequence where Element: AdditiveArithmetic { /// sum of the elements. /// ``` /// [1, 2, 3, 4, 5].sum // 15 /// ``` public var sum: Element { reduce(.zero, +) } } let sum = [1, 2, 3, 4, 5].sum // 15
Jesse โฉ Exploring Swiftโs numeric types and protocols
SwiftDoc โฉ Numeric
Swift โฉ Numbers and Basic Values โฉ Numeric Protocols โฉ Numeric
Sequence extension (where Element: AdditiveArithmetic) .
Last updated 2 years ago