Yes, Matthew, I agree with you exactly on this. It&#39;s tricky. `copyOf` isn&#39;t ideal at all, but `mutating` is potentially misleading. Ah the difficulties of naming things.<br><br><br><div class="gmail_quote"><div dir="ltr">On Tue, Jan 24, 2017 at 09:15 Matthew Johnson &lt;<a href="mailto:matthew@anandabits.com">matthew@anandabits.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">On Jan 24, 2017, at 8:12 AM, Chris Eidhof &lt;<a href="mailto:chris@eidhof.nl" class="gmail_msg" target="_blank">chris@eidhof.nl</a>&gt; wrote:</div><br class="m_-4020808097603061242Apple-interchange-newline gmail_msg"><div class="gmail_msg"><div dir="ltr" class="gmail_msg">But if we want to add &quot;copyOf&quot; we should do that to every method that takes a struct? Also, what if you pass in an object?<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I see the concern, but I don&#39;t think adding `copyOf` will increase clarity. That said, I&#39;m open to suggestions.</div></div></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg">I’m not really trying to advocate for “copyOf”.  I think we should really have something more concise in a case like this.  My main point is that just using `mutating` is inaccurate and therefore probably not the right solution.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Your question about passing in an object (I assume you mean a reference type here) is a good one.  In an ideal world that would probably not be allowed as it doesn’t really make sense to replace the reference during reduction.  Unfortunately I don’t think we have a way to prevent that at the moment.</div></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg"><div class="gmail_extra gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg">On Tue, Jan 24, 2017 at 2:43 PM, Xiaodi Wu <span dir="ltr" class="gmail_msg">&lt;<a href="mailto:xiaodi.wu@gmail.com" class="gmail_msg" target="_blank">xiaodi.wu@gmail.com</a>&gt;</span> wrote:<br class="gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">It&#39;s only verbose if the words aren&#39;t needed! The shortest way to describe something with sufficient accuracy can never be verbose, let alone undesirable, and I highly agree with this concern. We already have names of this form, such as `FloatingPoint.init(signOf:magnitudeOf:)`.</blockquote></div></div></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg">I mostly agree with this Xiaodi, but I also think that commonly known and frequently used methods like `reduce` deserve to be as concise as possible.  That is less a concern with less common and less frequently used signatures.</div></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg"><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="m_-4020808097603061242HOEnZb gmail_msg"><div class="m_-4020808097603061242h5 gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Tue, Jan 24, 2017 at 07:33 Matthew Johnson via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">Sent from my iPad</div></div><div dir="auto" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">On Jan 24, 2017, at 1:54 AM, Chris Eidhof via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div><blockquote type="cite" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><div dir="ltr" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">I&#39;ve thought about it for a few days, and really like `reduce(mutating:_)`. </div></div></blockquote><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div></div><div dir="auto" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">I&#39;m not a fan of this.  It reads in a way that makes it seem like the parameter should be inout, but it isn&#39;t.  A variation of reduce where the initial value parameter *is* inout is perfectly sensible (whether or not we want it in the standard library).  With that in mind, I don&#39;t think we should use this name.  </div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">Unfortunately I don&#39;t have a better suggestion.  I think it was Brent who suggested &quot;mutatingCopyOf&quot; which is more accurate, but also undesirably verbose.</div></div><div dir="auto" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><blockquote type="cite" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><div dir="ltr" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">I&#39;ve updated the PR, and am now happy for this to go into review.<div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><a href="https://github.com/apple/swift-evolution/pull/587" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg" target="_blank">https://github.com/apple/swift-evolution/pull/587</a><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div></div><div class="gmail_extra m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><div class="gmail_quote m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">On Mon, Jan 23, 2017 at 8:27 AM, Russ Bishop <span dir="ltr" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">&lt;<a href="mailto:xenadu@gmail.com" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg" target="_blank">xenadu@gmail.com</a>&gt;</span> wrote:<br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><blockquote class="gmail_quote m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><blockquote type="cite" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><span class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">On Jan 22, 2017, at 10:56 PM, Chris Eidhof &lt;<a href="mailto:chris@eidhof.nl" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg" target="_blank">chris@eidhof.nl</a>&gt; wrote:</div><br class="m_-4020808097603061242m_-4754073581537561m_-5640155817801206975m_-7135271088127339095Apple-interchange-newline m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></span><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><span class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><div dir="ltr" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">Not as a direct reply to Russ, but just to reiterate: to me, there are two clear benefits of using the `inout` version of reduce:<br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">1. The performance (currently discussed at length)</div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">2. Readability (because we can use mutating methods on `inout` arguments).</div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">Even if the compiler were to optimize the unnecessary copy of `return arr + [el]` away, there are still a lot of other mutable methods that you might want to use within the reduce closure. So I think the proposal is still very valid even if the compiler optimizations would magically appear tomorrow.</div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">To push this proposal forward a little bit, I&#39;d like to come up with a good name. It seems like we shouldn&#39;t overload `reduce`, but choose a different name, so that we don&#39;t stress the typechecker. Any other suggestions?</div></div></span><div class="gmail_extra m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><span class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><div class="gmail_quote m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">On Mon, Jan 23, 2017 at 7:11 AM, Russ Bishop <span dir="ltr" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">&lt;<a href="mailto:xenadu@gmail.com" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg" target="_blank">xenadu@gmail.com</a>&gt;</span> wrote:</div></span>-- <br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><div class="m_-4020808097603061242m_-4754073581537561m_-5640155817801206975m_-7135271088127339095gmail_signature m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg" data-smartmail="gmail_signature">Chris Eidhof</div>
</div>
</div></blockquote></div><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">Sorry for the derail!</div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">reduce(mutating:_:) { } is still my favorite; You can take mutating to mean we will copy the value now but mutate it later.</div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">Some alternatives:</div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">reduce(forMutating:_:) { }</div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">reduce(forInout:_:) { }</div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">reduce(initial:_:) { }</div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">reduce(copying:mutate:) { }</div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">// just kidding...</div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">reduce(copyForLaterMutating:_:) { }</div></div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">It should definitely be some form of reduce. </div><span class="m_-4020808097603061242m_-4754073581537561m_-5640155817801206975HOEnZb m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><font color="#888888" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">Russ</div></font></span></div></blockquote></div><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br clear="all" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div>-- <br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><div class="m_-4020808097603061242m_-4754073581537561m_-5640155817801206975gmail_signature m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg" data-smartmail="gmail_signature">Chris Eidhof</div>
</div>
</div></blockquote><blockquote type="cite" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><div class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><span class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">_______________________________________________</span><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><span class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">swift-evolution mailing list</span><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><span class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><a href="mailto:swift-evolution@swift.org" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg" target="_blank">swift-evolution@swift.org</a></span><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><span class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg"></div></blockquote></div>_______________________________________________<br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">
swift-evolution mailing list<br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="m_-4020808097603061242m_-4754073581537561gmail_msg gmail_msg">
</blockquote></div>
</div></div></blockquote></div><br class="gmail_msg"><br clear="all" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div>-- <br class="gmail_msg"><div class="m_-4020808097603061242gmail_signature gmail_msg" data-smartmail="gmail_signature">Chris Eidhof</div>
</div>
</div></blockquote></div></div></blockquote></div>