<div dir="ltr">I think the nice thing about reduce is that you can use it to implement something in a single line, and directly return it. Making the first parameter inout would require you to write `var result = ....` and `return result` (and `result` will be mutable after the call to `reduce`). Typically, the initial value is some kind of empty value, so copying isn't a problem. In my usage, making the first parameter inout would make the code more verbose, decrease readability and not win too much.<div><br></div><div>I think that making initialValue an inout is a cool idea, but I don't think it's something for this proposal. (I'm open for good arguments, though).</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 18, 2017 at 1:48 PM, Georgios Moschovitis via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">the former gives a hint about what someFunction (and the for-loop) is doing.<br>
<br>
-g.<br>
<div class="HOEnZb"><div class="h5"><br>
> On 18 Jan 2017, at 2:32 PM, Jeremy Pereira via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
><br>
><br>
>> On 18 Jan 2017, at 12:26, Xiaodi Wu via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
>><br>
>> Thought: if the idea is performance and not drop-in replacement, why force the user to incur two copies? If the initial value were inout, this function would be more unambiguous even without a new name, and at _worst_ the user has to declare a variable with var, a worthwhile trade-off to save two copies.<br>
><br>
> That’s what I thought also until just now, but then why wouldn’t you just use a for … in loop?<br>
><br>
> i.e. instead of<br>
><br>
> var foo = 0<br>
> let bar: [SomeType] = ...<br>
><br>
> bar.reduce(mutating: &foo, someFunction)<br>
><br>
> You would write<br>
><br>
> var foo = 0<br>
> let bar: [SomeType] = …<br>
><br>
> for e in bar {<br>
> someFunction(&foo, e)<br>
> }<br>
><br>
> which is a bit more readable IMO<br>
</div></div><div class="HOEnZb"><div class="h5">> ______________________________<wbr>_________________<br>
> swift-evolution mailing list<br>
> <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br>
______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Chris Eidhof</div>
</div>