<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 24, 2017, at 12:36 PM, Pyry Jahkola via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto" class=""><div class=""><span class=""></span></div><div class=""><div class=""><br class=""></div><div class="">Freak Show wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div class="">Am I the only one who finds this incredibly ugly and hard to read?</div><div class=""><br class=""></div><div class="">This is more or less solved by inject:into: idiom. &nbsp;There is no reason for inout for this particular problem.</div></div></blockquote><br class=""><div class="">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=""><br class=""></div><div class="">But your comment brought another idea to mind: if `mutating:` is considered a bad name for a non-`inout` argument, how about `<b class="">reduce(into:combine:)`</b>, similar to what Karl suggested earlier in this thread?</div><div class=""><br class=""></div><div class="">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 `&amp;` at the call site either), and it's still easily found with auto-completion:</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; let counts = words.reduce(into: [:]) {</div></div><div class="">&nbsp; &nbsp; &nbsp; $0[$1] = ($0[$1] ?? 0) + 1</div><div class="">&nbsp; &nbsp; }</div></div></div></blockquote><div><br class=""></div><div>+1. &nbsp;This is concise and I think it captures the essence of what is happening pretty well!</div><div><br class=""></div><div>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. &nbsp;I believe I have done this in the past in my own code but don’t have an example handy.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="auto" class=""><div class=""><br class=""></div><div class="">— Pyry</div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>