[swift-evolution] Reduce with inout
Jeremy Pereira
jeremy.j.pereira at googlemail.com
Wed Jan 18 06:24:51 CST 2017
> On 18 Jan 2017, at 02:17, Xiaodi Wu via swift-evolution <swift-evolution at swift.org> wrote:
>
> 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`.
Why not also have that version?
var foo = 0
let bar: [SomeType] = ...
bar.reduce(mutating: &foo, someFunction)
// foo now contains the reduced bar
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
More information about the swift-evolution
mailing list