Making use of enum cases with a common base name

SE-0155 explicitly allows enum cases to have the same base name.

Enum cases should have distinct full names. Therefore, shared base name will be allowed:

enum SyntaxTree {
   case type(variables: [TypeVariable])
   case type(instantiated: [Type])

Do people know about/use this feature in practice? What kind of things do you use it for? I'd particularly interested in examples from existing real-world code (compared to hypothetical examples you might come up with on the spot). From my perspective, it seems confusing when trying to pattern match on such an enum, surely I must be missing something. :sweat_smile:

Note that the question here is specifically about same base names. I'm not trying to ask for use cases for other features introduced by SE-0155.

1 Like

I’ve used it like so:

enum Action {
  case seek(by: TimeInterval)
  case seek(to: TimeInterval)

When I used to model endpoints using enums I would often have the following:

enum Endpoint {
    /// Get all users
    /// /users
    case users

    /// Get user by id
    /// /users/:id
    case users(id: User.ID)

I no longer model endpoints that way, but I know of a handful of developers who do.


Yep, a little bit confuse when pattern match if let case .type(v)=expr
what type of v is, [TypeVariable] or [Type]? both can be matched