Vostra.Result
1.2.1
dotnet add package Vostra.Result --version 1.2.1
NuGet\Install-Package Vostra.Result -Version 1.2.1
<PackageReference Include="Vostra.Result" Version="1.2.1" />
<PackageVersion Include="Vostra.Result" Version="1.2.1" />
<PackageReference Include="Vostra.Result" />
paket add Vostra.Result --version 1.2.1
#r "nuget: Vostra.Result, 1.2.1"
#:package Vostra.Result@1.2.1
#addin nuget:?package=Vostra.Result&version=1.2.1
#tool nuget:?package=Vostra.Result&version=1.2.1
Vostra.Result
A lean, async-friendly, dependency-free Result<T> for .NET. Stop throwing exceptions for expected
failures and stop juggling success-flags and out-params: errors become ordinary, typed values the compiler
tracks for you. The happy path stays implicit, the failure path is typed, and there is no .Value that
hands you garbage on failure.
A method that can fail just returns Result<T> — a bare value or a bare error both convert to it implicitly,
with no Result.Ok / Result.Fail ceremony. A missing lookup bridges to a typed failure in one line:
public Result<Order> GetOrder(int id) =>
_db.Find(id).MapNullTo(() => Result.NotFoundError($"Order {id} not found"));
Consume it safely — the value is reachable only inside a branch that runs because it succeeded, so you can't forget to check:
string label = result.Match(onOk: o => $"#{o.Id}", onErr: errs => errs[0].Message);
if (result.TryGetValue(out var order)) { /* use order */ }
Compose without ever unwrapping. Each step runs only on success, the first error short-circuits the rest,
and async folds in with a single await — no .Result, no nested awaits:
Result<Receipt> receipt =
await GetOrderAsync(id)
.Ensure(o => o.IsPaid, "Not paid.") // false -> ValidationError
.Then(o => ChargeAsync(o)) // T -> Task<Result<U>>, short-circuits on error
.Map(r => r.Receipt);
When an operation can succeed as one of several shapes (not just value-or-error), say so in the type and match every arm exhaustively — the compiler makes sure you handle each one:
public Result<Pdf, Html> Render(Doc doc) =>
doc.PrefersPrint ? RenderPdf(doc) : RenderHtml(doc); // each arm (or an Error) converts implicitly
string mime = Render(doc).Match(
pdf => "application/pdf",
html => "text/html",
errs => errs[0].Code); // error branch always present
What you get:
readonly struct, zero happy-path allocation, zero runtime dependencies.- Built-in error kinds (
ValidationError,NotFoundError,ConflictError,AlreadyExistsError,UnauthorizedError,ForbiddenError,Error) with stableCode+ neutralErrorType—newone directly or discover them from IntelliSense via the matchingResult.NotFoundError(...)factories; extend by subclassingErrorBase. Map/Then/Tap/Ensure/MapError(plus targetedMapError<TError>), full async matrix, LINQ (from … select), andCombine.- Re-word or re-tag an error while keeping its concrete kind:
ErrorBase.WithMessage/WithCode/Prefix/WithMetadata/WithCausedBy. - Recovery:
Else(try an alternative),ElseReturn(fall back to a value),Ignore(drop a failure kind on a valuelessResult) — plusResult.Try(capture an exception as a failure),MapNullTo(nullable →Result), andHasError(type/code/<TError>). - Multi-success unions
Result<T1,T2>/Result<T1,T2,T3>— one of several typed success shapes, or an error — consumed via exhaustiveMatch/Switch. - Companion packages: Vostra.Result.AspNetCore (
Result→ HTTP), Vostra.Result.Testing (transport-neutral chain & assert over anyTask<Result<T>>), and Vostra.Result.AspNetCore.Testing (HTTP →Resulttest client).
Full walkthrough: see the Usage Guide.
| Product | Versions 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. 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 is compatible. 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. |
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Vostra.Result:
| Package | Downloads |
|---|---|
|
Vostra.Result.Testing
Transport-neutral testing toolkit for Vostra.Result — fluent chain-and-assert helpers over any Task<Result<T>> with rich diagnostics. Depends only on the core type. |
|
|
Vostra.Result.AspNetCore
ASP.NET Core HTTP mapping for Vostra.Result — Result<T> to IResult with RFC 7807 ProblemDetails. |
GitHub repositories
This package is not used by any popular GitHub repositories.