[swift-evolution] [Review] SE-0194: Derived Collection of Enum Cases

Paul Cantrell cantrell at pobox.com
Wed Jan 10 14:39:38 CST 2018

> On Jan 10, 2018, at 2:23 PM, Kevin Nattinger <swift at nattinger.net> wrote:
>> [...]
>> I don’t agree that the Collection should be Int-indexed. Source-order is not a very strong guarantee IMO, and it wouldn’t be good if people started writing things like "MyEnum.allValues[3]” to reference a specific case.
> So how do you propose to use allValues with a table view? That's one of the motivating examples, and probably the most common use case. Certainly the most common I've seen.

I assume the mildly inconvenient

    static let valuesForTableView = Array(MyEnum.allValues)

…or some such.

>> If you know the specific case you are looking for, just write it directly. If you found an interesting case while iterating allValues, remember its (opaque) index and come back to it later.
>> I’m not a fan of Int-indexes in general. It’s practical to allow it for Array, but in general, for generic Collections, I think it implies an awful lot of knowledge about the Collection’s contents.
>> - Karl
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution

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

More information about the swift-evolution mailing list