[swift-evolution] 100% bikeshed topic: DictionaryLiteral

Brent Royal-Gordon brent at architechies.com
Tue Jan 9 23:04:33 CST 2018


> On Jan 8, 2018, at 4:29 PM, Ben Cohen via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I’m canvassing for opinions on what it ought to be called.  Some suggestions so far:
> 
> - `AssociationCollection`: Following the term of art from some other languages. Slightly obscure-sounding to developers not already familiar. Also “association” and “associative” are confusingly similar, which brings back the is-this-a-dictionary problem.
> - `KeyValueCollection`: Problematic because key-value comes up in a totally different context in Cocoa.
> - `PairCollection`: “Pair” is kinda nondescript.
> - Do nothing. It’s not so bad.


I think the best solution by far would be to provide an `extension Array: ExpressibleByDictionaryLiteral where Element == (Key, Value)` conformance. Besides the name, `DictionaryLiteral` basically has the same semantics as `Array`, but an impoverished subset of its functionality; using `Array` would reduce the standard library's surface area *and* improve the usability of code which currently uses `DictionaryLiteral`.

The problem is that this isn't currently expressible in the type system. If we can, I would actually support including some kind of unprincipled private hack so we could say `where Element: _AnyTupleOfTwo`. It seems like enough of a win, in both surface area and functionality, to justify a little compiler weirdness. (And we don't need to test for `_AnyTupleOfTwo` conformance at runtime, so I don't think it's a problem if `is` and `as?` don't work.)

-- 
Brent Royal-Gordon
Architechies

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20180109/54c0ba41/attachment.html>


More information about the swift-evolution mailing list