[swift-evolution] [Proposal Draft] Provide Custom Collections for Dictionary Keys and Values

Paul Cantrell cantrell at pobox.com
Sun Oct 16 11:43:21 CDT 2016


> On Oct 15, 2016, at 8:34 PM, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
> on Fri Oct 14 2016, Paul Cantrell <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> 
>> A late-arriving strong +1 for me. The index-related stuff is elegant and much needed. I’m surprised
>> to learn that dict.keys and dict.values are copies and not already
>> views! 
> 
> They are views.


Oh, OK. I stand … er, type … corrected! I was thinking of this bit of the proposal:

> this approach requires a linear search through a dictionary's keys to find a match.
> 
> if dict.keys.contains("one") {
I had wrongly assumed in the past that contains() would forward to an efficient lookup against the underlying dictionary. That’s what surprised me. It clearly deserves fixing.

From that, I made the incorrect leap to assuming that dict.keys made a copy. On more careful rereading and a visit to the docs for LazyMapCollection, the problem is much clearer to me now! Thanks as always for setting me right on the details.

Cheers, P

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


More information about the swift-evolution mailing list