Skip to content

1.3 • Additive Reductions

Latest
Compare
Choose a tag to compare
@KyNorthstar KyNorthstar released this 30 Nov 20:24
a821470

This introduces a .reduce(_:) function to sequences whose elements conform to AdditiveArithmetic which assumes you're reducing into .zero:

// Before
bunchaNumbers.reduce(into: 0) { $0 = max($0, $1) }

// After
bunchaNumbers.reduce { $0 = max($0, $1) }

This also adds a convenience function .sum(), build on this new reducer:

// Before
bunchaNumbers.reduce(into: 0, +=)

// After
bunchaNumbers.sum()

Patch Notes

  • 1.3.0
    • #12: Added .reduce which assumes reducing into 0 when elements are additive

Full Changelog: 1.2.1...1.3.0