Comparing enum cases while ignoring associated values

I like that a lot. Also fairly natural to grok: “use case let when you care about the associated value and omit the let when you don’t.”

Totally agree — I’ve run into this exact issue multiple times too. Would love a clean way to compare just the case, ignoring associated values. Hope this gets some attention!

Not built-in, but Case Paths has O(1) lookups for this and more:

Foo.allCasePaths[foo] == Foo.allCasePaths[bar]

foo.is(\.string)
bar.is(\.number)

We'd love to retire the library for built-in solutions, but it's been many years since we first released it and there's been no real public movement in the language. So if you do leverage enums in your apps, the Case Paths package may help you write the kind of code you've been wanting to write.

2 Likes