[swift-evolution] Pre-proposal: CaseEnumerable protocol (derived collection of enum cases)
jtbandes at gmail.com
Wed Jan 20 11:01:59 CST 2016
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.
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>
> 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> 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
> > https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution