[swift-evolution] Reduce with inout

Karl Wagner razielim at gmail.com
Wed Jan 18 02:36:06 CST 2017

> On 18 Jan 2017, at 09:00, Anton Zhilin via swift-evolution <swift-evolution at swift.org> wrote:
> While realizing that this name can cause confusion, I'd still prefer `reduce(mutating:_:)`, because it looks like the only readable option to me.
> Whatever name will be picked, I agree that traditional reduce without mutation should retain its name.
> 2017-01-18 5:17 GMT+03:00 Xiaodi Wu via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>>:
> A serious possibility would be: `reduce(mutableCopyOf: x) { ... }`.
> It's verbose, but the nicer-looking `reduce(mutating: x) { ... }` is incorrect since, as Charles pointed out to Dave, it's not `x` that's mutated but rather a mutable copy of it, so it doesn't matter if `x` itself is declared with `let` or `var`. 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

I suppose as a second-choice I’d go for accumulate(into: with:):

[1, 2, 3].accumulate(into: 0, with: +=) 

even [1, 2, 3].accumulate(into: 0, with: -=) doesn’t look so bad IMO.

- Karl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170118/264f405b/attachment.html>

More information about the swift-evolution mailing list