<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, May 26, 2017 at 7:57 AM, Gwendal Roué 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">> Furthermore, this probably comes up most commonly with dictionaries, since they're a sequence of tuples. The element tuple for dictionaries has element labels (key: Key, value: Value), so instead of writing `{ tuple in let (key, value) = tuple; f(key, value) }`, you could use the implicit argument and write `{ f($0.key, $0.value) }`.<br>
><br>
> -Joe<br>
<br>
</span>I've migrated a project from Swift 3 to Swift 4 (relevant commit: <a href="https://github.com/groue/GRDB.swift/commit/4f26cbcacf7b783c9c503f2909f2eb03ef7930fe" rel="noreferrer" target="_blank">https://github.com/groue/GRDB.<wbr>swift/commit/<wbr>4f26cbcacf7b783c9c503f2909f2eb<wbr>03ef7930fe</a>)<br>
<br>
Joe is right, dictionaries, as handy as they are, are particularly affected. But $0 is hardly a panacea.<br>
<br>
What I regret the most with the change is the lost ability to give *relevant names* to tuple elements (and sometimes with the forced introduction of a phony variable that has no relevant name (like "pair").<br>
<br>
Here are below four examples of regressions introduced by SE-0110:<br>
<br>
Example 1<br>
- return columns.index { (column, _) in column.lowercased() == lowercaseName }<br>
+ return columns.index { $0.0.lowercased() == lowercaseName }<br>
<br>
Example 2 :<br>
- .map { (mappedColumn, baseColumn) -> (Int, String) in<br>
+ .map { (pair) -> (Int, String) in<br>
+ let mappedColumn = pair.key<br>
+ let baseColumn = pair.value<br>
<br>
Example 3 :<br>
- .map { (table, columns) in "\(table)(\(columns.sorted().<wbr>joined(separator: ", ")))" }<br>
+ .map { "\($0.key)(\($0.value.sorted()<wbr>.joined(separator: ", ")))" }<br>
<br>
Example 4 :<br>
- dictionary.first { (column, value) in column.lowercased() == orderedColumn.lowercased() }<br>
+ dictionary.first { $0.key.lowercased() == orderedColumn.lowercased() }<br>
<br>
Gwendal Roué</blockquote></div><div><br></div><div>I have also migrated a couple of projects, and this appeared in every one of them even if we didn't use any RX library. For example Alamofire has a couple of errors due to this change. And the resulting code after applying the Fix-It is, well, not pretty.</div><div><br></div><div>As you say, it will basically affect a lot of Dictionary API surface, not only forEach but map, filter, etc.</div><div><br></div><div>SE-0110 seems to hinder the functional programming style, and I would revert it because right now we know that the proposal was wrong as it stated that the impact on existing code may be that only "minor" changes to user code may be required:</div><div><a href="goog_1034749016"><br></a></div><div><a href="https://github.com/apple/swift-evolution/blob/master/proposals/0110-distingish-single-tuple-arg.md">https://github.com/apple/swift-evolution/blob/master/proposals/0110-distingish-single-tuple-arg.md</a></div><div><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,system-ui,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol"">Impact on existing code</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px">Minor changes to user code may be required if this proposal is accepted.</p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,system-ui,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol""><a id="gmail-user-content-alternatives-considered" class="gmail-anchor" href="https://github.com/apple/swift-evolution/blob/master/proposals/0110-distingish-single-tuple-arg.md#alternatives-considered" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none;float:left;padding-right:4px;line-height:1"></a>Alternatives considered</h2><p style="box-sizing:border-box;margin-top:0px;color:rgb(36,41,46);font-family:-apple-system,system-ui,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;margin-bottom:0px">Don't make this change.</p></div><div><br></div>-- </div><div class="gmail_extra">Víctor Pimentel<div class="gmail_signature"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr" style="font-size:12.8px"><div style="font-size:12.8px"></div></div></div></div></div></div></div></div></div></div></div></div>
</div></div>