[swift-evolution] Revisiting SE-0110

Dave Abrahams dabrahams at apple.com
Sat May 27 12:43:24 CDT 2017

on Thu May 25 2017, Gwendal Roué <swift-evolution at swift.org> wrote:

>> 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)
>> }`.
>> -Joe
> I've migrated a project from Swift 3 to Swift 4 (relevant commit:
> https://github.com/groue/GRDB.swift/commit/4f26cbcacf7b783c9c503f2909f2eb03ef7930fe)
> Joe is right, dictionaries, as handy as they are, are particularly affected. But $0 is hardly a
> panacea.
> 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").

Not saying there's no problem here, but `kv` (or `keyValue` if you must)
works pretty well for this.  At least it isn't purely a reflection of
the type and gives some hint as to semantics.


More information about the swift-evolution mailing list