[swift-evolution] Proposal: Enum 'count' functionality
Nevin Brackett-Rozinsky
nevin.brackettrozinsky at gmail.com
Mon Dec 21 10:27:31 CST 2015
Would .cases return the enum’s cases in source-code order? That seems
fragile at first glance.
It might be worth considering to have it return an unordered collection
(set) instead.
Nevin
On Mon, Dec 21, 2015 at 10:52 AM, Stephen Celis via swift-evolution <
swift-evolution at swift.org> wrote:
> Does the naming "values" have precedence elsewhere? To me, "cases" is
> clearer, whereas "rawValues" would make sense if there was an additional,
> auto-generated static property for enumerations with underlying values.
>
> enum Section: Int { case SectionA, Section B }
> Section.cases // [.SectionA, .SectionB]
> Section.rawValues // [0, 1]
>
> Because "rawValue" already exists, "values" makes things a bit more
> confusing: are they the cases themselves or are they their underlying
> values?
>
> Stephen
>
> On Dec 21, 2015, at 3:57 AM, Charles Constant via swift-evolution <
> swift-evolution at swift.org> wrote:
>
> If you change your proposal to focus on ".values" instead
> of ".values.count" (which you'd get for free, as you note) I would strongly
> support it. I don't need ".count" on its own, but ".values" ... well, I
> have a whole load of enums in my current projects with a ".values" I had to
> hardcode myself. I would love to get that for free.
>
> On Mon, Dec 21, 2015 at 12:46 AM, Brent Royal-Gordon via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>> > I’ve put a proposal up on GitHub to add a cases ‘count’ functionality
>> to Enums for the Swift language
>> > https://gist.github.com/andyyhope/2fc5b6bee8ee1346f688
>>
>> I think we'd be much better off having a list of all cases. That would
>> make this feature useful for enums which don't have a raw type, or don't
>> use Int as their raw type, or don't use sequential raw values for their
>> cases.
>>
>> That approach has been discussed before, but not formally proposed.
>>
>> --
>> Brent Royal-Gordon
>> Architechies
>>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
>
> _______________________________________________
> swift-evolution mailing list
> 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/20151221/148b4ca6/attachment.html>
More information about the swift-evolution
mailing list