mcintyre321/OneOf
View on GitHub ↗ ★ 4,060 C#
Easy to use F#-like ~discriminated~ unions for C# with exhaustive compile time matching
29 mentions on Hacker News by 10 people: 3 stories, 26 comments · first 2016-08-25 · latest 2026-02-01
20082026
-
…from F# over the years. It's up to the team. [0] https://github.com/amantinband/error-or [1] https://github.com/mcintyre321/OneOf [2] https://timdeschryver.dev/blog/pattern-matching-examples-in-... [3]…
comment by CharlieDigital · 2026-02-01 · in The history of C# and TypeScript with Anders Hejlsberg [video] -
…Name A good OneOf implementation is here (I have nothing to do with this library, I just like it): https://github.com/mcintyre321/OneOf I wrote a JsonConverter for OneOf and just pass those over the wire.
comment by feoren · 2025-10-08 · in What .NET 10 GC changes mean for developers -
…to get access to DU [0] https://timdeschryver.dev/blog/pattern-matching-examples-in-... [1] https://github.com/mcintyre321/OneOf [2] https://github.com/domn1995/dunet
comment by CharlieDigital · 2025-10-05 · in What .NET 10 GC changes mean for developers -
…Why would I want to use this instead of a more general approach to discriminated unions, eg. like: https://github.com/mcintyre321/OneOf If I would use your library I would need a separate solution for every other case. Take care, Martin
comment by jerleth · 2025-08-13 · in ManagedCode.Communication – a complete Result Pattern project for .NET -
There's also OneOf ( https://github.com/mcintyre321/OneOf ) as well which feels more ergonomic to me (having used both). Practical example in a short write up here: https://chrlschn.dev/blog/2024/07/csharp-discriminated-union...
comment by CharlieDigital · 2024-10-31 · in A comparison of Rust’s borrow checker to the one in C# -
…example of using this: https://chrlschn.dev/blog/2024/07/csharp-discriminated-union... [0] https://github.com/mcintyre321/OneOf [1] https://github.com/domn1995/dunet
comment by CharlieDigital · 2024-10-18 · in Net 9.0 LINQ Performance Improvements -
…allows your models to evolve over time without changing your function signatures at the edge. [0] https://github.com/mcintyre321/OneOf
comment by conor- · 2024-08-08 · in Official proposal for Type Unions in C# -
…to add DUs in C# today with some third party packages. - https://github.com/domn1995/dunet - https://github.com/mcintyre321/OneOf Quite good and ergonomic with the source generators removing a lot of the boilerplate. I have a practical…
comment by CharlieDigital · 2024-08-07 · in Official proposal for Type Unions in C# -
…hn.dev/blog/2023/08/dotnet-source-generators-d... [2] https://www.youtube.com/watch?v=GlnEm7JyvyY [3] https://github.com/mcintyre321/OneOf
comment by CharlieDigital · 2024-05-16 · in Swift sucks at web serving or does it? -
Until that feature lands there's this https://github.com/mcintyre321/OneOf which is pretty nice.
comment by conor- · 2023-10-20 · in What's new in C# 12: overview -
Agree. 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 ).
comment by ftcHn · 2023-08-07 · in The combined power of F# and C# -
…it's usually a class type. 1) https://learn.microsoft.com/en-us/dotnet/api/system.nullable... 2) https://github.com/mcintyre321/OneOf/blob/master/OneOf/OneOf...
comment by SideburnsOfDoom · 2023-03-13 · in Overhead of Returning Optional Values in Java and Rust (2021) -
Apologies, but here's the obligatory link to my OneOf exhaustive type matching library: https://github.com/mcintyre321/OneOf
comment by macca321 · 2020-02-04 · in C# Pattern Matching -
I maintain a library for doing exactly this in C# ( https://github.com/mcintyre321/OneOf ). I tried to replicate it in Python as I'm writing it at the moment, but couldn't quite manage it. Can you have a multi generic typed Union in python?
comment by macca321 · 2019-12-08 · in Statically-typed error handling in Python using Mypy -
You can get a pretty reasonable facsimile using some libraries I made: Discriminated unions: https://github.com/mcintyre321/OneOf and One line value objects: https://github.com/mcintyre321/ValueOf
comment by macca321 · 2019-05-22 · in A whirlwind tour of object-oriented code in F# (2012) -
... and exhaustive matching: https://github.com/mcintyre321/OneOf I'm not saying it's as good as writing F#, or that C# shouldn't include these features of course.
comment by macca321 · 2019-05-22 · in A whirlwind tour of object-oriented code in F# (2012) -
If you're after Option or ADTs (Unions) for C#, I can heartily recommend https://github.com/mcintyre321/OneOf , it's brilliant. But then I would say that ;)
comment by macca321 · 2018-11-09 · in What Makes .NET Core So Special? -
…what types get passed in, nor can you ensure that all possible types actually get handled. [1]: https://github.com/mcintyre321/OneOf/
comment by coldacid · 2018-03-12 · in Tuples goodness in .NET 4.7.1 -
We're singing from the same hymn sheet :) https://github.com/mcintyre321/OneOf https://github.com/mcintyre321/ValueOf
comment by macca321 · 2017-08-17 · in The Problem with F# Evangelism -
We're singing from the same hymn sheet https://github.com/mcintyre321/OneOf https://github.com/mcintyre321/ValueOf
comment by macca321 · 2017-08-16 · in The Problem with F# Evangelism -
…I don't know if this would work in Java, given the generic type erasure, but it might... 1. https://github.com/mcintyre321/OneOf
comment by macca321 · 2017-04-20 · in Pattern Matching for Java -
…at the lack of exhaustive matching / Discriminated Unions, please try out my library OneOf* ( https://github.com/mcintyre321/OneOf ). Hopefully something similar will be brought into C# soon, but in the meantime, these libraries provide…
comment by macca321 · 2017-03-10 · in New Features in C# 7.0 -
I'm just going to pimp my library (github.com/mcintyre321/OneOf) which lets you pull this off in c#. I'm quite sad it's needed though, it would be great to have it in the language.
comment by macca321 · 2016-08-25 · in What’s New in C# 7.0 -
You can achieve something similar via a library: https://github.com/mcintyre321/OneOf I also think language level support for this would be a killer feature, it turns OOP and the requirement to use polymorphism to guarantee…
comment by macca321 · 2016-08-25 · in What’s New in C# 7.0