Hmm, brainstorming here. Given the pervasive use of `with` to mean "this isn't accessible otherwise but inside this closure it's $0", maybe `reduce(with: 42) { $0 += 1 }` might give a useful hint?<br><div class="gmail_quote"><div dir="ltr">On Tue, Jan 24, 2017 at 13:19 Matthew Johnson <<a href="mailto:matthew@anandabits.com">matthew@anandabits.com</a>> 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 1:01 PM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" class="gmail_msg" target="_blank">xiaodi.wu@gmail.com</a>> wrote:</div><br class="m_-610305470151524434Apple-interchange-newline gmail_msg"><div class="gmail_msg">Hmm, it reads well, but IMO it avoids being misleading only because it doesn't mean anything. In what way are you reducing "into" the first argument any more so than the classic reduce function?</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">It isn't perfect, but it’s better than the alternatives I’ve seen so far.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">In the classic reduce function a new value is produced for each step of the reduction. In this variation, each step reduces “into” an accumulator that is initialized with the seed value. In that sense, you could say that you reduce “into” the seed value.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Labeling the argument `into` is a little bit of a stretch but I think it's far superior to `mutating` which is pretty misleading at the call site. I think it would be pretty hard to come up with something better, but let’s keep the bikeshed going if anyone has additional ideas.</div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Tue, Jan 24, 2017 at 12:44 Matthew Johnson via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>> 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 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 12:36 PM, Pyry Jahkola via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br class="gmail_msg m_-610305470151524434m_4877748158606825571Apple-interchange-newline"><div class="gmail_msg"><div dir="auto" class="gmail_msg"><div class="gmail_msg"><span class="gmail_msg"></span></div><div class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Freak Show wrote:<br class="gmail_msg"><br class="gmail_msg"></div><blockquote type="cite" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg">Am I the only one who finds this incredibly ugly and hard to read?</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">This is more or less solved by inject:into: idiom. There is no reason for inout for this particular problem.</div></div></blockquote><br class="gmail_msg"><div class="gmail_msg">Yeah, the original signature seems more useful. If you go all `inout` like Gwendal suggested, you might as well just iterate over the sequence with `for x in xs`, updating the state as you go.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">But your comment brought another idea to mind: if `mutating:` is considered a bad name for a non-`inout` argument, how about `<b class="gmail_msg">reduce(into:combine:)`</b>, similar to what Karl suggested earlier in this thread?</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I think it reads very well at the call site, does not suggest `inout`ness of the argument too much (of course there's no `&` at the call site either), and it's still easily found with auto-completion:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"> let counts = words.reduce(into: [:]) {</div></div><div class="gmail_msg"> $0[$1] = ($0[$1] ?? 0) + 1</div><div class="gmail_msg"> }</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">+1. This is concise and I think it captures the essence of what is happening pretty well!</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">The third variation where the seed argument actually *is* `inout` might also be interesting in some cases where you *already* have a `var` that you want to accumulate into. I believe I have done this in the past in my own code but don’t have an example handy.</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 dir="auto" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">— Pyry</div></div>_______________________________________________<br class="gmail_msg">swift-evolution mailing list<br class="gmail_msg"><a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg"></div></blockquote></div></div>_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div>
</div></blockquote></div><br class="gmail_msg"></div></blockquote></div>