Skip to content

Comment on Dart 3.3parent

Comments

You might already know of this since you mentioned pattern matching, but there is the `sealed` class modifier which allows for exhaustive matching on class subtypes. It's very limited: https://dart.dev/language/class-modifiers#sealed

I recall there being a reason unions aren't generally implemented, though I'm not sure where I read it. It was to do with union types being unnecessarily complex for the compiler and the code they tend to produce, at no real benefit to the programmer or the resulting program. Go's lack of unions is essentially based around the same reasoning.

It looks like it's an open discussion for Dart, but I can't see any explicit plans for an implementation.

The sealed class with the switch case pretty much solves my issue cleanly, thanks!

Nice, I know hardly anything about Dart so I’m glad what little I know was of use.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.