Implementation of Discriminated Union and Pattern Matching in C#.

string outputValue = x.Match<String>()
.Case(c => c == "Test", v => "It's Test!")
.Case(v => "It's Not Test!")
.Else(() => "It's None!")

var x = new Union<string, int>(100);

// the type annotations below are optional and only added for clerity.
string value = x.Match<string>()
.Case((string v) => v)
.Case((int c) => c == 100, (int v) => "Keeping It 100.")
.Case((int v) => "Tea?")
.Else(() => "Nothing");

Assert.Equal("Keeping It 100.", value);

Install-Package DiscriminatedUnion -Version
dotnet add package DiscriminatedUnion --version
<PackageReference Include="DiscriminatedUnion" Version="" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DiscriminatedUnion --version
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DiscriminatedUnion,"
For F# scripts that support #r syntax, copy this into the source code to reference the package.


This package has no dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on DiscriminatedUnion:

Package Downloads
DiscriminatedUnion AutoMap Helper.
DiscriminatedUnion Json Converter

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated 967 8/4/2017 553 8/4/2017 553 7/24/2017