[swift-evolution] Proposal: Always flatten the single element tuple

Gwendal Roué gwendal.roue at gmail.com
Thu Jun 8 13:26:40 CDT 2017

> Le 8 juin 2017 à 20:17, Gwendal Roué <gwendal.roue at gmail.com> a écrit :
> This gives us the ability to deal with unfitted function signatures. For example, most Dictionary methods. Yes, they are usually unfitted:
>     extension Dictionary {
>         func forEach(_ body: ((key: Key, value: Value)) throws -> Void) rethrows
>     }
> Who cares about this named (key:value:) tuple? Absolutely nobody, as exemplified by this remarquable Swift 3 snippet below, where no tuple, no `key`, and no `value` is in sight:
>     let scores: [String: Int] = ... // [playerName: score]
>     scores.forEach { name, score in
>         print("\(name): \(score)")
>     }
> Do you see?

I regret my "Absolutely nobody" snippet. Some people like the `key` and `value` identifiers.

Those people are the people who write the standard library, people who write blog posts about Swift novelties, and people who write experimental software around Swift. All very valuable people.

There are other kinds of developers, who don't really care about the beauty of dictionary design and implementation. They just want a container that does what it's supposed to do: map stuff to other stuff. Not keys to values.

To them, a dictionary is like a screwdriver: when you use it, you don't want to think about it much.

And the recent changes force us to see uninteresting implementation details that obscure everyday code.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170608/5285039d/attachment.html>

More information about the swift-evolution mailing list