[swift-evolution] Pre-proposal: CaseEnumerable protocol (derived collection of enum cases)

Joe Groff jgroff at apple.com
Wed Jan 20 12:04:09 CST 2016


> On Jan 20, 2016, at 9:01 AM, Jacob Bandes-Storch via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I've been thinking about naming a bit. I'm worried that "values" / "allValues" won't make sense if this feature eventually goes in the direction of returning type constructors. For enums with associated types, the cases may actually be functions taking the associated type and returning the enum type. (There's an example under "Future directions" in the proposal). Calling these "values" seems strange to me, but calling them "cases" makes sense.

That seems like a fairly specialized use case to me. I'd expect the default behavior for enums with associated values to enumerate all possible values of each case (whose associated values would themselves need to be ValueEnumerable), not the case constructors themselves. That's more generally useful when using associated values to categorize constants.

-Joe

> Even though the "case" keyword is mostly used with enums, I think the actual English word "case" applies pretty well when thinking about any type, not just enums. It refers to a member of the type. T.cases or T.allCases are all the cases of valid instances/members of the type.
> 
> "FiniteType" is technically accurate, but to me it doesn't evoke "this protocol allows you to enumerate the type's values". I'm leaning toward the names that end in -Enumerable.
> 
> Unless someone has a compelling argument otherwise, I may leave the naming as-is in the proposal, and let the core team bikeshed it to their liking :)
> 
> On Wed, Jan 20, 2016 at 8:45 AM, Denis Nikitenko <d.nikitenko at icloud.com <mailto:d.nikitenko at icloud.com>> wrote:
> For the protocol name, I rather like FiniteType (or FiniteValueType), since I find it to be more general and future-proof.  ValueEnumerable would also work, though.
> 
> My preference for the static var would be T.values or T.allValues - we want to get all values of the finite type T.
> 
> Definitely a +1 on the overall proposal.
> 
> 
> 
> >> On Jan 18, 2016, at 11:15 PM, Jacob Bandes-Storch via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> >>
> >>
> >> OK, I can see the argument here. I was worried about making this proposal so broad that it wouldn't be seriously considered, but I agree that choosing more general names will open it up to future expansion.
> >>
> >> Here are some more name ideas:
> >>
> >> - CaseEnumerable (in the proposal draft)
> >> - T.cases (in the proposal draft)
> >> - T.allCases
> >> - FiniteType (as you suggested)
> >> - FiniteValueType
> >> - ValueEnumerable
> >> - T.values
> >> - T.allValues
> >>
> >> Thoughts? More suggestions? I think I like ValueEnumerable.
> >>
> >
> > _______________________________________________
> > 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/20160120/796e2dcc/attachment.html>


More information about the swift-evolution mailing list