[swift-evolution] Pre-proposal: CaseEnumerable protocol (derived collection of enum cases)
Step C
schristopher at bignerdranch.com
Mon Jan 18 22:31:50 CST 2016
Happy to see this proposal. Comments inline.
> On Jan 18, 2016, at 7:21 PM, Howard Lovatt via swift-evolution <swift-evolution at swift.org> wrote:
>
> +1 from me. Minor changes I would suggest are:
>
> 1. All enums implicitly implement `CaseEnumerable`, so that you do not have to remember to add it.
I think explicit is better, particularly since this could have resilience implications. Changing the order of cases (or properties) can break your API, which is not true for plain enums currently. Though this means extensions that add conformance could still be fragile. Another option would be to require all cases to explicitly be listed again, but with compiler support to make sure the list is complete. That may be too verbose though.
> 2. That `CaseEnumerable` has exploit static members `cases` and `caseFromName`. So that `CaseEnumerable` can be useful outside of `enum` constructs. In Java the equivalent of `caseFromName` has proved beneficial.
`caseFromName` takes a String?
> 3. That `cases` is a `Set<String>`, i.e. a more specific collection.
>
>> On Monday, 18 January 2016, Jacob Bandes-Storch via swift-evolution <swift-evolution at swift.org> wrote:
>> Hi folks,
>>
>> I've drafted a proposal to add a CaseEnumerable protocol, which will derive a static variable "cases" for enum types. Feedback is welcome, especially for refining the proposal before I submit a formal PR.
>>
>> The draft is here; full text below. https://github.com/jtbandes/swift-evolution/blob/977a9923fd551491623b6bfd398d5859488fe1ae/proposals/0000-derived-collection-of-enum-cases.md
>>
>>
>> Derived Collection of Enum Cases
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160118/0dbc66b3/attachment.html>
More information about the swift-evolution
mailing list