It seems like enums should have a way to refer to 'the base case without associated values'

You could, but you would still need to provide to the function an array of values that are fully qualified, not just base cases.

Let's say that there's a "same case" operator, and that you use it to write an isIn function. If might be ok for simple enums in some simple cases, but consider an enum like this:

enum Foo {
case bar(Int)
case baz(String)
case bam(Bool)
}

Say that you have this instance

let value = Foo.baz("yello")

and you want to use the isIn function (that, remember, only checks the base case) to see if your value is of case bar or baz. You would need to call the isIn like this:

value.isIn([.bar(...what should you put here?...), `.baz(...same question...)])

you can see that the .bar and .baz instances that you put in the Array can have arbitrary associated values (because isIn only checks the base case) which makes no sense and clearly signals that value-based comparison is not the right too for the job.

You can't, because you can't pass an "array of patterns". The way you do this in Swift is, again, with switch, to match a value against one or more patterns.

Maybe, but if you want to push for this concept (that, as I mentioned, seems perfectly legit to me), you'll need better examples, because your case is already solved in Swift using different features.

I'm fine with the if case syntax, it makes perfect sense to me, even if it's a little cumbersome to use (there's an ongoing discussion to improve it in simple cases).

But I see that you're trolling here, and you're not interested in discussing realistic options, the actual features language and how they work, so I'll happily leave the conversation.

1 Like