News for hackers. Stuff that matters.
Re:Flutter 2 by svieira on Wednesday March 03, 2021 @05:10PM (#26335411)
The proper analog to union types in Dart (as in Java) is enums and / or church-encoding [I think that's the term] generalized algebraic data types (GADTs). E. g. something like this: https://gist.github.com/jbgi/208a1733f15cdcf78eb5

Scala 2 also had `sealed` classes that could be used in places where you needed enums parameterized by runtime values and that's been generalized in Scala 3 IIRC.

Re:Flutter 2 by okamiueru on Wednesday March 03, 2021 @05:26PM (#26335653)
I'm certainly confused now whether or not we are talking about the same thing. Without delving to much on the use of the word "union", how would you solve the use case presented in the typescript examples using enums?
Re:Flutter 2 by okamiueru on Wednesday March 03, 2021 @09:57PM (#26338069)
Reading more about it, it could seem that we are talking about the same thing, except that it was so far over my head, that I didn't realise it.