ResultType 2.0.0

This library offers an elegant and efficient way of handling errors known as railway programming.

Install-Package ResultType -Version 2.0.0
dotnet add package ResultType --version 2.0.0
<PackageReference Include="ResultType" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ResultType --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

NuGet License

| Build server | Build status |
|--------------|--------------|
| Travis | Build Status |

ResultType is an implementation of Result type for C#.

This library offers an elegant and efficient way of handling errors known as railway programming.
Result object holds the desired value or error message. Thanks to that, ResultType allows you to deal with errors without resorting to using exceptions.
It's really easy to use and can be used alongside exceptions in order to build a system where expected errors are handled using ResultType and unexpected errors are thrown as exceptions.

How it works?

The library contains two types that implement Result<T> abstract class - Success and Error.

Getting started

The basic feature of ResultType is holding value or error.
Let's look at an examples:

var result = ResultFactory.CreateSuccess(value);

Example of an error:

var result = ResultFactory.CreateError("error message");

It's possible to create Success without value:

var result = ResultFactory.CreateSuccess(value);

In this case value of type Nothing is stored.
To unpack value you have to call GetValue() method:

var unpackedValue = result.GetValue();

Unpacking error is simillar:

var upackedValue = result.GetError();

If you call GetValue() method on Error or GetError on Success, InvalidOperationException will be thrown.

It is really easy to check if result is success:

var isSucces = result.IsSuccess();

or error:

var isSucces = result.IsError();

You can chain functions that returns Result type using cotinuations:

public Result<Nothing> SomeFunction(Result<Nothing> result)
{
    return result.Continue(() => ResultFactory.CreateSuccess());
}

When you call Continue() method, it checks if the result is Success or Error. If it is Success then provided lambda expresion is executed. In other case error message is propagated.

It's possible to pass value from previous expresion as argument.

public Result<string> SomeFunction(Result<Nothing> result)
{
    return result.Continue(s => ResultFactory.CreateSuccess(s));
}

Tasks thar returns Result can also be chained using Continue method.

public async Task<Result<string>> SomeFunction(Result<Nothing> result)
{
    return await result.Continue(s => ResultFactory.CreateSuccess(s));
}
public async Task<Result<string>> SomeFunction(Result<Nothing> result)
{
    return await result.Continue(async s => await SomeAsyncFunction(s));
}

NuGet License

| Build server | Build status |
|--------------|--------------|
| Travis | Build Status |

ResultType is an implementation of Result type for C#.

This library offers an elegant and efficient way of handling errors known as railway programming.
Result object holds the desired value or error message. Thanks to that, ResultType allows you to deal with errors without resorting to using exceptions.
It's really easy to use and can be used alongside exceptions in order to build a system where expected errors are handled using ResultType and unexpected errors are thrown as exceptions.

How it works?

The library contains two types that implement Result<T> abstract class - Success and Error.

Getting started

The basic feature of ResultType is holding value or error.
Let's look at an examples:

var result = ResultFactory.CreateSuccess(value);

Example of an error:

var result = ResultFactory.CreateError("error message");

It's possible to create Success without value:

var result = ResultFactory.CreateSuccess(value);

In this case value of type Nothing is stored.
To unpack value you have to call GetValue() method:

var unpackedValue = result.GetValue();

Unpacking error is simillar:

var upackedValue = result.GetError();

If you call GetValue() method on Error or GetError on Success, InvalidOperationException will be thrown.

It is really easy to check if result is success:

var isSucces = result.IsSuccess();

or error:

var isSucces = result.IsError();

You can chain functions that returns Result type using cotinuations:

public Result<Nothing> SomeFunction(Result<Nothing> result)
{
    return result.Continue(() => ResultFactory.CreateSuccess());
}

When you call Continue() method, it checks if the result is Success or Error. If it is Success then provided lambda expresion is executed. In other case error message is propagated.

It's possible to pass value from previous expresion as argument.

public Result<string> SomeFunction(Result<Nothing> result)
{
    return result.Continue(s => ResultFactory.CreateSuccess(s));
}

Tasks thar returns Result can also be chained using Continue method.

public async Task<Result<string>> SomeFunction(Result<Nothing> result)
{
    return await result.Continue(s => ResultFactory.CreateSuccess(s));
}
public async Task<Result<string>> SomeFunction(Result<Nothing> result)
{
    return await result.Continue(async s => await SomeAsyncFunction(s));
}

  • .NETCoreApp 2.2

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.0.0 124 4/1/2019
1.0.1 506 2/10/2019
1.0.0 283 6/2/2018