[swift-evolution] Proposal: Enum 'count' functionality

Erica Sadun erica at ericasadun.com
Mon Dec 21 14:09:01 CST 2015


My wild aspirations in a nutshell:

Core enums:  Any enum that's created without raw or associated values, e.g. enum MyEnum {case This, That, Whatever, Etc},  can (and should) be Array<Self> representable. This would add intrinsic ordering and raw value construction starting with 0, up to count - 1. End-devs could use the ordering or not use the ordering, but it would be possible to convert to bit representation (1 << this.rawValue),  support iteration through the enumeration, introduce ranges for switches, etc. A massive improvement.

Raw value enums: Any enum that uses raw values, e.g. enum ForExample: String {case Hello = "hello", There = "there"} should be representable as Set<T>

Associated type enums: all bets are off

-- E

> On Dec 21, 2015, at 12:52 PM, Jacob Bandes-Storch via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I brought up this topic a couple weeks ago in a thread called "List of all Enum values (for simple enums)":
> 
> https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/001233.html <https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/001233.html>
> 
> I suppose it's time to start synthesizing those ideas/discussion into a proposal :)
> 
> Jacob
> 
> On Mon, Dec 21, 2015 at 8:35 AM, Stephen Celis via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> On Dec 21, 2015, at 11:27 AM, Nevin Brackett-Rozinsky <nevin.brackettrozinsky at gmail.com <mailto:nevin.brackettrozinsky at gmail.com>> wrote:
>> 
>> 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.
> 
> Care to elaborate on why you think it may be fragile?
> 
> Retaining order makes sense to me given that integer-backed enumerations auto-increment and that enumerations cannot be extended with new cases. I'm not opposed to using a set, though, if that makes more sense.
> 
> Stephen
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <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/e4a64465/attachment.html>


More information about the swift-evolution mailing list