Assured 0.1.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Assured --version 0.1.1
NuGet\Install-Package Assured -Version 0.1.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Assured" Version="0.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Assured" Version="0.1.1" />
<PackageReference Include="Assured" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Assured --version 0.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Assured, 0.1.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Assured@0.1.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Assured&version=0.1.1
#tool nuget:?package=Assured&version=0.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
<p align="center"><img src="https://raw.githubusercontent.com/0x2E757/Assured/main/assets/logo-512.png" alt="Assured" width="128"></p>
Assured
Result<TValue, TError> for C#: a value or an error, never both, never neither by accident.
using Assured;
Result<int, string> Parse(string text) {
return int.TryParse(text, out var number) ? number : $"not a number: {text}";
}
if (Parse(input).TryUnwrapValue(out var value))
Console.WriteLine(value);
API at a glance
Grouped by what you want to do; see the XML documentation for exact signatures.
| Need | Members |
|---|---|
| Create | Result<V, E>.Value(v), Result<V, E>.Error(e), or assign a V or E directly (implicit conversion) |
| Inspect | HasValue(), HasError() |
| Take the contents, or throw | UnwrapValue(), UnwrapError() |
| Take the contents, checked | TryUnwrapValue(out v), TryUnwrapError(out e) |
| Take the contents, or a substitute | ValueOr(fallback), ValueOrGenerate(() => fallback) |
| Handle both cases in one expression | Match(onValue, onError) |
| Transform without unwrapping | Map(f) for the value, MapError(f) for the error, Bind(f) to chain a call that returns another Result |
| Compare | ==, !=, Equals, GetHashCode; usable as a dictionary key |
| Success without data | Success.Value as the value of Result<Success, E> |
Design
- State is explicit. A result holds a value or an error because it was created through the
ValueorErrorfactory, or through the implicit conversion fromTValueorTError. State is never inferred fromnullordefault, so value types and nullable references work the same way. defaultis not a result. A struct can always be obtained uninitialized:default,new(), an array element, an unassigned field. Such a result reports neither a value nor an error. Accessors that must produce something throw; combinators that transform the contents pass it through unchanged. Do not construct this state on purpose; for a success that carries no data useResult<Success, TError>.- Readonly struct, no hidden allocations. Creating, copying, comparing and inspecting a result does not allocate. The only allocations the library can cause are the delegates the caller passes to combinators; how much a delegate allocates depends on what it captures and on the C# compiler version, not on this library.
- Equality is by state and contents. Two results are equal when they are in the same state and their active field compares equal with the default comparer for its type.
Conventions for code that uses Assured
- Return
Resultfrom any operation that can fail in a way the caller is expected to handle. Exceptions are for bugs and unrecoverable failures. - Check the state before unwrapping, or use the
Try*and*Or*accessors. Unwrapping an unchecked result is the mistake this library exists to prevent. - Prefer non-capturing lambdas or pre-created delegates in hot paths when calling combinators.
- Keep the return type as
Resulteven while a method cannot fail yet; adding the first error later then changes only the method, not its callers.
Where to look
- The public API is small and lives in the
Assuredproject; each concern is a separate partial file ofResult. - XML documentation is generated and shipped with the package, so IDE tooltips describe every public member.
- Compatibility targets and the language version are declared in the project file.
License
MIT, see LICENSE.
| 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 | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- 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.