nuv.Result
7.2.0
dotnet add package nuv.Result --version 7.2.0
NuGet\Install-Package nuv.Result -Version 7.2.0
<PackageReference Include="nuv.Result" Version="7.2.0" />
<PackageVersion Include="nuv.Result" Version="7.2.0" />
<PackageReference Include="nuv.Result" />
paket add nuv.Result --version 7.2.0
#r "nuget: nuv.Result, 7.2.0"
#:package nuv.Result@7.2.0
#addin nuget:?package=nuv.Result&version=7.2.0
#tool nuget:?package=nuv.Result&version=7.2.0
nuv.Result
basic Result type implementation
Declaring results
// declare "Ok" variant explicitly:
// Result<TValue, TError>.Ok(TValue)
var okResult = new Result<string, int>.Ok("everything went ok");
// Result.Ok<TValue, TError>(TValue)
var okResult = Result.Ok<string, int>("everything went ok");
// or implicitly:
Result<string, int> implicitOkResult = "everything went ok";
// declare "Error" variant explicitly
// Result<TValue, TError>.Error(TError)
var errorResult = new Result<string, int>.Error(1);
// Result.Error<TValue, TError>(TError)
var errorResult = Result.Error<string, int>(1);
// or implicitly:
Result<string, int> implicitErrorResult = 1;
Returning results
public Result<string, int> SomeFallibleFunction() // success example
{
// explicitly:
return new Result<string, int>.Ok("everything went ok");
// or implicitly:
return "everything went ok";
}
public Result<string, int> SomeFallibleFunction() // fail example
{
// explicitly:
return new Result<string, int>.Error(1);
// or implicitly:
return 1;
}
Applying functions to values
okResult.Map(x => x.Length)
// -> Ok(19)
okResult
.Map(x => Ok(x.Length)) // -> Ok(Ok(19))
.Flatten() // -> Ok(19)
okResult.Try(x => Ok(x.Length))
// -> Ok(19)
errorResult.Map(x => x.Length)
// -> Error(1)
okResult.MapError(x => x + 1)
// -> Ok(19)
errorResult.MapError(x => x + 1)
// -> Error(2)
Checking for Ok / Error
okResult.IsOk()
// -> true
okResult.IsError()
// -> false
errorResult.IsOk()
// -> false
errorResult.IsError()
// -> true
Getting error / ok values
errorResult.UnwrapError(0);
// -> 1
okResult.UnwrapError(0);
// -> 0
errorResult.Unwrap("whoops");
// -> "whoops"
okResult.Unwrap("whoops");
// -> "everything went ok"
Pattern matching
// with a normal switch statement
switch (okResult)
{
case Result<string, int>.Ok ok:
Console.WriteLine(ok.Value);
break;
case Result<string, int>.Error error:
Console.WriteLine(error.Value);
break;
}
// or with the build in .match function
okResult.Match(
ok => Console.WriteLine(ok),
error => Console.WriteLine(error)
);
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.Text.Json (>= 9.0.4)
-
.NETStandard 2.1
- System.Text.Json (>= 9.0.4)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on nuv.Result:
| Package | Downloads |
|---|---|
|
nuv.Option
Basic option type |
|
|
nuv.Result.SwaggerGen
Basic SwaggerGen integration for nuv.Option |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 7.2.0 | 144 | 11/28/2025 |
| 7.1.0 | 180 | 10/1/2025 |
| 7.0.0 | 303 | 9/17/2025 |
| 6.6.0 | 309 | 8/25/2025 |
| 6.5.0 | 178 | 5/26/2025 |
| 6.4.0 | 178 | 5/26/2025 |
| 6.3.0 | 180 | 5/26/2025 |
| 6.2.0 | 176 | 5/21/2025 |
| 6.1.0 | 221 | 5/19/2025 |
| 6.0.1 | 262 | 5/14/2025 |
| 6.0.0 | 265 | 5/14/2025 |
| 5.2.0 | 264 | 5/13/2025 |
| 5.1.0 | 249 | 5/13/2025 |
| 5.0.0 | 433 | 5/13/2025 |
| 4.1.0 | 229 | 5/7/2025 |
| 4.0.0 | 285 | 4/14/2025 |
| 3.0.2 | 217 | 3/27/2025 |
| 3.0.1 | 161 | 3/27/2025 |
| 3.0.0 | 219 | 3/27/2025 |
| 2.0.1 | 591 | 3/26/2025 |
v.7.2.0
- Add ReplaceValue function
- Change license to Apache-2.0
v.7.1.0
- Rename type arguments from "T", "TE", "Tr" and "TEr" to "OK", "ERROR", "OKAFTER" and "ERRORAFTER" respectively
- Add .ConfigureAwait(false) to async await functions
- Add variant of TryCatch that takes a Func<Exception, ERROR> used to convert the exception to a known error type
v.7.0.0
- Map(arg, Action<T>) renamed to Tap(arg, Action<T>)
- MapError(arg, Action<T>) renamed to TapError(arg, Action<T>)
- Added FromNullable and ToNullable
v.6.6.0
- Add TryCatch wrapper for both Result -> Result and T -> Result
- Add Or and LazyOr
v.6.5.0
- Add ReplaceError
v.6.4.0
- Add MatchAsync
v.6.3.0
- Add MapAsync and TryAsync
- Add Result.Ok<T> and .Error<T> with Exception as their default error value for convenience
v.6.2.0
- Add Action<> version of Match
v.6.1.0
- Registered ConverterFactory on Result<T,E>. No longer needs to be manually enabled.
v.6.0.1
- Fix Match(Func, Func) implementation
v.6.0.0
- Added Match(Func, Func)
- Moved some functions from Result to Result<TValue, TError>
v.5.2.0
- Fix Implementation error in ResultConverter that would Return Ok in Error case
v.5.1.0
- Add MapError variant that takes Action<TValue>
v.5.0.0
- Change Result<TValue, TError> to be an abstract class with private ctor.
- Ok/Error are now proper variants of Result
- Required changes *should* be minimal
- This makes proper serialization using System.Text.Json possible
-> Add "new ResultConverterFactory()" to your JsonSerializationOptions.Converters to enable
v.4.1.0
- Add implicit conversions for TValue and TError for convenience
- Removed Obsolete marker from Ok/Error<TValue, TError> variants
v.4.0.0
- Move Ok() and Error() from Result to Result<TValue, TError>
-> Made constructor private, Ok() and Error() now the only way to create a new instance
-> Added Result.Ok<TValue, TError>() and Result.Error<TValue, TError>() variants for backward compatability, marked as obsolete
--> Prefer Result<TValue, TError>.Ok() and Result<TValue, TError>.Error() going forward
v.3.0.2
- Change Result type to be class instead of record
-> To improve ergonomics when chaining .Map and such
v.3.0.1
- Add new Result.Map variant that takes an Action<T>
v.3.0.0
- Add proper nuv.Result namespace
v.2.0.1
- Add support for NETStandard 2.0
v.2.0.0
- Fix Result.Try() implementation
- Add function summaries
v.1.0.0
- Initial Release