Option.Either 1.0.0

Install-Package Option.Either -Version 1.0.0
dotnet add package Option.Either --version 1.0.0
<PackageReference Include="Option.Either" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Option.Either --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Option.Either, 1.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Option.Either as a Cake Addin
#addin nuget:?package=Option.Either&version=1.0.0

// Install Option.Either as a Cake Tool
#tool nuget:?package=Option.Either&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Either

Creates a simple struct that can be used as discriminated union like return type, supporting the successful result as well as up to four additonal exceptions that can be returned.

Example using the built in Resolve method

public IActionResult Get(Guid id)
{
   return  _repository.User(id)
                      .Resolve<IActionResult>(
                          user => Ok(user),
                          error => NotFound()
                      );
}

Example using C# pattern mathcing

public IActionResult Post([FromBody] UserCreateRequest request)
{
    var result = _repository.Create(request.Email, request.Name);
            
    return result.Value switch
    {
        Guid guid =>  Created(guid.ToString(), guid),
        ArgumentException ex => BadRequest(new { ex.Message, request }),
        InvalidDataContractException ex => BadRequest(new { ex.Message, request }),
        _ => ServerError()
    };
}
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 125 2/1/2021
0.0.1 267 8/20/2020

Logo: Pat Hawks / CC BY-SA (https://creativecommons.org/licenses/by-sa/4.0)