CommonTypeUnions 1.0.1

dotnet add package CommonTypeUnions --version 1.0.1                
NuGet\Install-Package CommonTypeUnions -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CommonTypeUnions" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CommonTypeUnions --version 1.0.1                
#r "nuget: CommonTypeUnions, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CommonTypeUnions as a Cake Addin
#addin nuget:?package=CommonTypeUnions&version=1.0.1

// Install CommonTypeUnions as a Cake Tool
#tool nuget:?package=CommonTypeUnions&version=1.0.1                

GitHub license Contributor Covenant GitHub issues

Common Union Types

[!WARNING] Type Unions are in the early proposal stage and will likely see changes as time goes on, we plan to keep up with these changes as much as possible to ensure the easiest migration path once type unions make it into a stable .net version.

This library contains a set of commonly used type unions.

Type unions are an upcoming feature that is proposed for a future version of C#. We try our best to keep the types in this library as close as possible to the proposal as possible to make a transition to future Type Unions as easy as possible.

Getting Started

You can get started using these types by simply installing the CommonTypeUnions package from nuget.

Alternatively you can install it using the dotnet cli:

dotnet add package CommonTypeUnions --version 1.0.0

Option<TValue>

Option is a struct union found in many languages, it can either represent a value that is something (Some) or nothing (None).

using CommonTypeUnions.Unions;
using static CommonTypeUnions.Extensions.OptionExtensions;

Option<string> x = Some("text");
Option<string> y = None();

if (x.IsSome(out var value))
{
    Console.WriteLine($"Value: {value}");
}

var isNone = y.IsNone();

Console.WriteLine($"Is None: {isNone}");

Output:

Value: text
Is None: True

Result<TValue, TError>

Option is a struct union found in many languages, it is used to either represent a successful result (Success) or error (Failure) from a function.

using CommonTypeUnions.Unions;
using static CommonTypeUnions.Extensions.ResultExtensions;

Result<int, string> x = Success(42);
Result<int, string> y = Failure("Oh no");

if (x.IsSuccess(out var value))
{
    Console.WriteLine($"Value: {value}");
}

if (y.IsFailure(out var error))
{
    Console.WriteLine($"Failure: {error}");
}

Output:

Value: 42
Failure: Oh no
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on CommonTypeUnions:

Repository Stars
ChromaControl/ChromaControl
3rd party device lighting support for Razer Synapse.
Version Downloads Last updated
1.0.1 563 8/4/2024
1.0.0 79 8/4/2024