What does HackerNews think of OneOf?
Easy to use F#-like ~discriminated~ unions for C# with exhaustive compile time matching
Dunet is really good.
https://github.com/mcintyre321/OneOf
https://github.com/domn1995/dunet
It's on the roadmap and will arrive at some point:
https://github.com/dotnet/csharplang/blob/main/proposals/dis...
For now, you can get a reasonable DU via an [external library](https://github.com/mcintyre321/OneOf).
[Nick Chapsas Video on Usage](https://www.youtube.com/watch?v=7z-xjijYfcI).
Discriminated unions: https://github.com/mcintyre321/OneOf and One line value objects: https://github.com/mcintyre321/ValueOf
I'm not saying it's as good as writing F#, or that C# shouldn't include these features of course.
But then I would say that ;)
https://github.com/mcintyre321/OneOf https://github.com/mcintyre321/ValueOf
Each type has a `.Match` and `.Switch` methods, in to which you have to pass lambdas to handle each case `.Match(Func`.
I don't know if this would work in Java, given the generic type erasure, but it might...
Also, ValueUtils (https://www.nuget.org/packages/ValueUtils/) is nice for making value types.
*or one of the many alternatives (https://www.nuget.org/packages?q=discriminated+unions) e.g. SuccincT, DiscU
I also think language level support for this would be a killer feature, it turns OOP and the requirement to use polymorphism to guarantee strategy-per-type on it's head.