<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I think you're all fighting against the language, and especially against `inout`. Because you try to copy and then mutate a value, instead of mutating it right away.<div class=""><br class=""></div><div class="">I totally understand why: `inout` requires variable declared `var`, and the compiler won't auto-generate it for us. We try to avoid polluting our code with those extra `var` variables. They make code look messy.</div><div class=""><br class=""></div><div class="">But what if we stop fighting? Isn't the following code the correct version of Chris's vision ?</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(130, 53, 160);" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3c5aa7" class="">Sequence</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures;" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> reduce&lt;A&gt;(mutating result: </span><span style="font-variant-ligatures: no-common-ligatures;" class="">inout</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #1f7fa0" class="">A</span><span style="font-variant-ligatures: no-common-ligatures" class="">, </span><span style="font-variant-ligatures: no-common-ligatures;" class="">_</span><span style="font-variant-ligatures: no-common-ligatures" class=""> combine: (inout </span><span style="font-variant-ligatures: no-common-ligatures; color: #1f7fa0" class="">A</span><span style="font-variant-ligatures: no-common-ligatures" class="">, Iterator.Element) -&gt; ()) {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures;" class="">for</span><span style="font-variant-ligatures: no-common-ligatures" class=""> element </span><span style="font-variant-ligatures: no-common-ligatures;" class="">in</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures;" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; combine(&amp;result, element)</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3c5aa7" class="">Sequence</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures;" class="">where</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Iterator.Element: Equatable {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures;" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> uniq() -&gt; [Iterator.Element] {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures;" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> result: [Iterator.Element] = [] </span><span style="font-variant-ligatures: no-common-ligatures; color: #008f00" class="">// meh</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #1f7fa0" class="">reduce</span><span style="font-variant-ligatures: no-common-ligatures" class="">(mutating: &amp;result) { (result: </span><span style="font-variant-ligatures: no-common-ligatures;" class="">inout</span><span style="font-variant-ligatures: no-common-ligatures" class=""> [Iterator.Element], element) </span><span style="font-variant-ligatures: no-common-ligatures;" class="">in</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures;" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class=""> result.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3c5aa7" class="">last</span><span style="font-variant-ligatures: no-common-ligatures" class=""> != element {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3c5aa7" class="">append</span><span style="font-variant-ligatures: no-common-ligatures" class="">(element)</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures;" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> result</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> x = [1, 1, 2, 3]</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #1f7fa0" class="">x</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #1f7fa0" class="">uniq</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">() </span><span style="font-variant-ligatures: no-common-ligatures" class="">// [1, 2, 3]</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div></div><div class="">Yes, the extra `var` variable in the implementation of `uniq` is awful. But that's a limitation of `inout`. Not a limitation of your imagination when you try to find a good name for your method.</div><div class=""><br class=""></div><div class="">I'd suggest us to think about improving Swift so that it starts generating those extra `var` variables for us. It would then give:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #8235a0" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> f(i: </span><span style="font-variant-ligatures: no-common-ligatures; color: #8235a0" class="">inout</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3c5aa7" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">) { ... }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #1f7fa0" class="">f</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(1) </span><span style="font-variant-ligatures: no-common-ligatures" class="">// OK, even if mutated result is lost</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #8235a0" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> x: </span><span style="font-variant-ligatures: no-common-ligatures; color: #3c5aa7" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = 2</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #1f7fa0" class="">f</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(x) </span><span style="font-variant-ligatures: no-common-ligatures" class="">// OK, even if mutated result is lost</span></div></div><div class=""><br class=""></div><div class="">And reduce(mutating:) would get rid of the extra var:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(130, 53, 160);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3c5aa7" class="">Sequence</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #8235a0" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> reduce&lt;A&gt;(mutating result: </span><span style="font-variant-ligatures: no-common-ligatures; color: #8235a0" class="">inout</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #1f7fa0" class="">A</span><span style="font-variant-ligatures: no-common-ligatures" class="">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #8235a0" class="">_</span><span style="font-variant-ligatures: no-common-ligatures" class=""> combine: (inout </span><span style="font-variant-ligatures: no-common-ligatures; color: #1f7fa0" class="">A</span><span style="font-variant-ligatures: no-common-ligatures" class="">, Iterator.Element) -&gt; ()) -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #1f7fa0" class="">A</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #8235a0" class="">for</span><span style="font-variant-ligatures: no-common-ligatures" class=""> element </span><span style="font-variant-ligatures: no-common-ligatures; color: #8235a0" class="">in</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #8235a0" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; combine(&amp;result, element)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #8235a0" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> result</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #8235a0" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3c5aa7" class="">Sequence</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #8235a0" class="">where</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Iterator.Element: Equatable {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #8235a0" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> uniq() -&gt; [Iterator.Element] {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #8235a0" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> reduce(mutating: []) { (result: </span><span style="font-variant-ligatures: no-common-ligatures; color: #8235a0" class="">inout</span><span style="font-variant-ligatures: no-common-ligatures" class=""> [Iterator.Element], element) </span><span style="font-variant-ligatures: no-common-ligatures; color: #8235a0" class="">in</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #8235a0" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class=""> result.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3c5aa7" class="">last</span><span style="font-variant-ligatures: no-common-ligatures" class=""> != element {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3c5aa7" class="">append</span><span style="font-variant-ligatures: no-common-ligatures" class="">(element)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span></div></div><div class="">Gwendal</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">Le 24 janv. 2017 à 15:12, Chris Eidhof via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; a écrit :</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">But if we want to add "copyOf" we should do that to every method that takes a struct? Also, what if you pass in an object?<div class=""><br class=""></div><div class="">I see the concern, but I don't think adding `copyOf` will increase clarity. That said, I'm open to suggestions.</div></div><div class="gmail_extra" style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""><div class="gmail_quote">On Tue, Jan 24, 2017 at 2:43 PM, Xiaodi Wu<span class="Apple-converted-space">&nbsp;</span><span dir="ltr" class="">&lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank" class="">xiaodi.wu@gmail.com</a>&gt;</span><span class="Apple-converted-space">&nbsp;</span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">It's only verbose if the words aren'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:<wbr class="">magnitudeOf:)`.<div class="HOEnZb"><div class="h5"><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Tue, Jan 24, 2017 at 07:33 Matthew Johnson via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div dir="auto" class="m_-4754073581537561gmail_msg"><div class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg">Sent from my iPad</div></div><div dir="auto" class="m_-4754073581537561gmail_msg"><div class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg">On Jan 24, 2017, at 1:54 AM, Chris Eidhof via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="m_-4754073581537561gmail_msg" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"></div><blockquote type="cite" class="m_-4754073581537561gmail_msg"><div class="m_-4754073581537561gmail_msg"><div dir="ltr" class="m_-4754073581537561gmail_msg">I've thought about it for a few days, and really like `reduce(mutating:_)`.<span class="Apple-converted-space">&nbsp;</span></div></div></blockquote><div class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"></div></div><div dir="auto" class="m_-4754073581537561gmail_msg"><div class="m_-4754073581537561gmail_msg">I'm not a fan of this.&nbsp; It reads in a way that makes it seem like the parameter should be inout, but it isn't.&nbsp; A variation of reduce where the initial value parameter *is* inout is perfectly sensible (whether or not we want it in the standard library).&nbsp; With that in mind, I don't think we should use this name. &nbsp;</div><div class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"></div><div class="m_-4754073581537561gmail_msg">Unfortunately I don't have a better suggestion.&nbsp; I think it was Brent who suggested "mutatingCopyOf" which is more accurate, but also undesirably verbose.</div></div><div dir="auto" class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"><blockquote type="cite" class="m_-4754073581537561gmail_msg"><div class="m_-4754073581537561gmail_msg"><div dir="ltr" class="m_-4754073581537561gmail_msg">I've updated the PR, and am now happy for this to go into review.<div class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"></div><div class="m_-4754073581537561gmail_msg"><a href="https://github.com/apple/swift-evolution/pull/587" class="m_-4754073581537561gmail_msg" target="_blank">https://github.com/apple/<wbr class="">swift-evolution/pull/587</a><br class="m_-4754073581537561gmail_msg"></div></div><div class="gmail_extra m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"><div class="gmail_quote m_-4754073581537561gmail_msg">On Mon, Jan 23, 2017 at 8:27 AM, Russ Bishop<span class="Apple-converted-space">&nbsp;</span><span dir="ltr" class="m_-4754073581537561gmail_msg">&lt;<a href="mailto:xenadu@gmail.com" class="m_-4754073581537561gmail_msg" target="_blank">xenadu@gmail.com</a>&gt;</span><span class="Apple-converted-space">&nbsp;</span>wrote:<br class="m_-4754073581537561gmail_msg"><blockquote class="gmail_quote m_-4754073581537561gmail_msg" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div class="m_-4754073581537561gmail_msg" style="word-wrap: break-word;"><br class="m_-4754073581537561gmail_msg"><div class="m_-4754073581537561gmail_msg"><blockquote type="cite" class="m_-4754073581537561gmail_msg"><span class="m_-4754073581537561gmail_msg"><div class="m_-4754073581537561gmail_msg">On Jan 22, 2017, at 10:56 PM, Chris Eidhof &lt;<a href="mailto:chris@eidhof.nl" class="m_-4754073581537561gmail_msg" target="_blank">chris@eidhof.nl</a>&gt; wrote:</div><br class="m_-4754073581537561m_-5640155817801206975m_-7135271088127339095Apple-interchange-newline m_-4754073581537561gmail_msg"></span><div class="m_-4754073581537561gmail_msg"><span class="m_-4754073581537561gmail_msg"><div dir="ltr" class="m_-4754073581537561gmail_msg"><div class="m_-4754073581537561gmail_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_-4754073581537561gmail_msg"></div><div class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"></div><div class="m_-4754073581537561gmail_msg">1. The performance (currently discussed at length)</div><div class="m_-4754073581537561gmail_msg">2. Readability (because we can use mutating methods on `inout` arguments).</div><div class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"></div><div class="m_-4754073581537561gmail_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_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"></div><div class="m_-4754073581537561gmail_msg">To push this proposal forward a little bit, I'd like to come up with a good name. It seems like we shouldn't overload `reduce`, but choose a different name, so that we don't stress the typechecker. Any other suggestions?</div></div></span><div class="gmail_extra m_-4754073581537561gmail_msg"><span class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"><div class="gmail_quote m_-4754073581537561gmail_msg">On Mon, Jan 23, 2017 at 7:11 AM, Russ Bishop<span class="Apple-converted-space">&nbsp;</span><span dir="ltr" class="m_-4754073581537561gmail_msg">&lt;<a href="mailto:xenadu@gmail.com" class="m_-4754073581537561gmail_msg" target="_blank">xenadu@gmail.com</a>&gt;</span><span class="Apple-converted-space">&nbsp;</span>wrote:</div></span>--<span class="Apple-converted-space">&nbsp;</span><br class="m_-4754073581537561gmail_msg"><div class="m_-4754073581537561m_-5640155817801206975m_-7135271088127339095gmail_signature m_-4754073581537561gmail_msg" data-smartmail="gmail_signature">Chris Eidhof</div></div></div></blockquote></div><br class="m_-4754073581537561gmail_msg"><div class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"></div><div class="m_-4754073581537561gmail_msg">Sorry for the derail!</div><div class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"></div><div class="m_-4754073581537561gmail_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_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"></div><div class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"></div><div class="m_-4754073581537561gmail_msg">Some alternatives:</div><div class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"></div><div class="m_-4754073581537561gmail_msg">reduce(forMutating:_:) { }</div><div class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"></div><div class="m_-4754073581537561gmail_msg">reduce(forInout:_:) { }</div><div class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"></div><div class="m_-4754073581537561gmail_msg">reduce(initial:_:) { }</div><div class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"></div><div class="m_-4754073581537561gmail_msg">reduce(copying:mutate:) { }</div><div class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"></div><div class="m_-4754073581537561gmail_msg"><div class="m_-4754073581537561gmail_msg">// just kidding...</div><div class="m_-4754073581537561gmail_msg">reduce(copyForLaterMutating:_:<wbr class="">) { }</div></div><div class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"></div><div class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"></div><div class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"></div><div class="m_-4754073581537561gmail_msg">It should definitely be some form of reduce.&nbsp;</div><span class="m_-4754073581537561m_-5640155817801206975HOEnZb m_-4754073581537561gmail_msg"><font color="#888888" class="m_-4754073581537561gmail_msg"><div class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"></div><div class="m_-4754073581537561gmail_msg">Russ</div></font></span></div></blockquote></div><br class="m_-4754073581537561gmail_msg"><br clear="all" class="m_-4754073581537561gmail_msg"><div class="m_-4754073581537561gmail_msg"><br class="m_-4754073581537561gmail_msg"></div>--<span class="Apple-converted-space">&nbsp;</span><br class="m_-4754073581537561gmail_msg"><div class="m_-4754073581537561m_-5640155817801206975gmail_signature m_-4754073581537561gmail_msg" data-smartmail="gmail_signature">Chris Eidhof</div></div></div></blockquote><blockquote type="cite" class="m_-4754073581537561gmail_msg"><div class="m_-4754073581537561gmail_msg"><span class="m_-4754073581537561gmail_msg">______________________________<wbr class="">_________________</span><br class="m_-4754073581537561gmail_msg"><span class="m_-4754073581537561gmail_msg">swift-evolution mailing list</span><br class="m_-4754073581537561gmail_msg"><span class="m_-4754073581537561gmail_msg"><a href="mailto:swift-evolution@swift.org" class="m_-4754073581537561gmail_msg" target="_blank">swift-evolution@swift.org</a></span><br class="m_-4754073581537561gmail_msg"><span class="m_-4754073581537561gmail_msg"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="m_-4754073581537561gmail_msg" target="_blank">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-<wbr class="">evolution</a></span><br class="m_-4754073581537561gmail_msg"></div></blockquote></div>______________________________<wbr class="">_________________<br class="m_-4754073581537561gmail_msg">swift-evolution mailing list<br class="m_-4754073581537561gmail_msg"><a href="mailto:swift-evolution@swift.org" class="m_-4754073581537561gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="m_-4754073581537561gmail_msg"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="m_-4754073581537561gmail_msg" target="_blank">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-<wbr class="">evolution</a><br class="m_-4754073581537561gmail_msg"></blockquote></div></div></div></blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div>--<span class="Apple-converted-space">&nbsp;</span><br class=""><div class="gmail_signature" data-smartmail="gmail_signature">Chris Eidhof</div></div><span style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></div></div></body></html>