5 ms·
you can easily do them, I added a comment on the article showing how.... https://github.com/linkdotnet/Blog.Discussions/discussions/73#discussioncomment-666314
by keithnz 3y ago
you can easily do them, I added a comment on the article showing how....
https://github.com/linkdotnet/Blog.Discussions/discussions/73#discussioncomment-6663149 https://github.com/linkdotnet/Blog.Discussions/discussions/7...
- LelouBil 3y agoIt's just like in Kotlin !
- Turskarama 3y agoIt's missing the killer feature though, which is the compiler warning you when you haven't done an exhaustive match. That is the magic which makes adding new values easy instead of hunting through code to find if you missed the new case anywhere.
- mycall 3y agoI've only needed discriminated unions inside C# when I'm using pinvoke to C DLLs. I would think Rosylin supports some compiler warning for them, but I haven't checked that.
- keithnz 3y agoI used to think that.... but actually, in practice, and I've been using them for a long time now, it doesn't make much difference, good tooling will generate the cases and help you find all instances pretty quick (I use Rider).
- Rapzid 3y agoMy guess is roles will land first in C#13. Is is kind of a pain particularly when working across Typescript projects. OneOf is cool, but it DOES NOT work well with null and thus optional parameters.
- rjbwork 3y agoThis is the kind of OG way to do it even before we had patterns. There are a couple of problems with it, least of which is that I can't then use one or both of those in a wider union elsewhere, because their definitions are bound to that parent class. Ideally I'd like to see something very similar to the linked OneOf library. That allows you to do both in-line definitions OR subclass from OneOf<T1,T2,T3...> to reify the union as a class as well. If that is done and integrated properly into the pattern matching system, I believe it will yield very powerful expressiveness.