Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I retrofitted F# style "discriminated unions" (which are basically sealed heirarchies) into C# by creating a series of generic types `OneOf<T0, ..., Tn>` which can hold exactly one value,

Each type has a `.Match` and `.Switch` methods, in to which you have to pass lambdas to handle each case `.Match(Func<T0, TResult, ..., Func<Tn, TResult>`.

I don't know if this would work in Java, given the generic type erasure, but it might...

1. https://github.com/mcintyre321/OneOf



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: