Skip to content
Nuvyntra Labs
All packages

Shared libraries

Result

A success value or a typed error without throwing

Result<T> and Result for a call that can fail without throwing. A page checks IsSuccess. Version 0.1.1 is in source and is not on nuget.org yet.

Install

dotnet add package NuvyntraLabs.NET.Result

Package ID: NuvyntraLabs.NET.Result

NuvyntraLabs.NET.* is a class library, not a Plugin.Maui.* package. The install command applies after 0.1.1 is published. Until then, reference the project in the hub submodule.

Example

Result<User> found = Result<User>.Success(user);
Result<User> missing = Result<User>.Failure(new NotFoundError("User is missing."));
Result done = Result.Success();
string label = found.Match(value => value.Name, error => error.Code);

Overview

NuvyntraLabs.NET.Result returns a success value or an Error. Prefer ErrorOr when the host wants a larger result library. Value throws InvalidOperationException on failure. Error throws on success. Failure(null) throws ArgumentNullException. Match is the only functional method. There is no Map, Bind, or LINQ operator, and no ASP.NET Core ProblemDetails adapter.

Capabilities

  • Result<T> is a success value or an Error. Result is success or an Error with no value.
  • Error requires a Code and a Message.
  • ValidationError uses code validation and adds a property name.
  • NotFoundError uses code not_found.
  • Match is the read path. There is no Map, Bind, or LINQ operator.

Discussion

Comment on NuvyntraLabs.NET.Result. The thread lives on this component's GitHub repository. Sign in with GitHub — Giscus uses Discussions, Utterances uses Issues.

Issues are not enabled on this repository

Open the conversation on GitHub, or use the Giscus tab if Discussions are available.

Related in Shared libraries