Throwaway.Core
1.0.0
dotnet add package Throwaway.Core --version 1.0.0
NuGet\Install-Package Throwaway.Core -Version 1.0.0
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="Throwaway.Core" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Throwaway.Core" Version="1.0.0" />
<PackageReference Include="Throwaway.Core" />
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 Throwaway.Core --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Throwaway.Core, 1.0.0"
#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 Throwaway.Core@1.0.0
#: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=Throwaway.Core&version=1.0.0
#tool nuget:?package=Throwaway.Core&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Throwaway
Exception-free error handling for C#. A lightweight Result pattern library with Roslyn analyzers that guide you toward explicit, composable error handling.
Overview
Throwaway provides:
Result<T>andResulttypes - Explicit success/failure containers that replace exceptions for business logic- Rich composition operators -
Bind,Map,Match,Tap,Combine,TrySelect,OrElse, and more - Heterogeneous Combine - Compose Results of different types into tuples
- Roslyn analyzers with code fixes - Detect anti-patterns and guide refactors in real-time
Installation
dotnet add package Throwaway.Core
dotnet add package Throwaway.CodeAnalysis.Analyzers
Quick Start
using Throwaway.Core;
public Result<User> GetUser(string id)
{
// Explicit success or failure
var userResult = await _db.GetUserAsync(id);
if (userResult == null)
return Result<User>.Failure(Error.NotFound("User not found"));
return Result<User>.Success(userResult);
}
// Consume with explicit handling
userResult.Match(
user => Console.WriteLine($"Hello {user.Name}"),
error => Console.WriteLine($"Error: {error.Message}")
);
// Or pipeline operations
userResult
.Bind(user => LoadPreferences(user.Id))
.Tap(prefs => Console.WriteLine($"Loaded {prefs.Count} preferences"))
.MapError(error => Error.Internal("Failed to load user"));
Heterogeneous Combine
Combine independent Results of different types into a single tuple Result:
using Throwaway.Core;
using static Throwaway.Core.Result;
var nameResult = ValidateName(input.Name);
var emailResult = ValidateEmail(input.Email);
var ageResult = ValidateAge(input.Age);
var combined = Result.Combine(nameResult, emailResult, ageResult);
combined.Match(
(name, email, age) => CreateUser(name, email, age),
error => HandleError(error)
);
Async version with parallel execution:
var combined = await Result.CombineAsync(
ValidateNameAsync(input.Name),
ValidateEmailAsync(input.Email),
ValidateAgeAsync(input.Age)
);
Result Patterns
Bind (chain fallible operations)
userResult
.Bind(user => LoadPreferences(user.Id))
.Bind(prefs => ApplyTheme(prefs.SelectedTheme));
Map (transform success values)
userResult.Map(user => user.Name.ToUpper());
Match (handle both branches)
userResult.Match(
user => $"Hello {user.Name}",
error => $"Error: {error.Message}"
);
Tap (side effects)
userResult.Tap(user => _logger.LogInformation("Got user {UserId}", user.Id));
TrySelect (apply fallible operations to collections)
var userIds = new[] { 1, 2, 3 };
var results = await userIds.TrySelectAsync(id => GetUserAsync(id));
// Returns all successes OR first failure
OrElse (fallback on failure)
var result = await GetFromCacheAsync(key)
.OrElse(() => GetFromDatabaseAsync(key))
.OrElse(() => Result<User>.Success(DefaultUser));
Destructured Binding on Combined Results
Result.Combine(
ValidateName(name),
ValidateEmail(email),
ValidateAge(age)
).Bind((validName, validEmail, validAge) =>
CreateUser(validName, validEmail, validAge)
);
Analyzer Diagnostics
The analyzer package detects and helps fix common anti-patterns:
| ID | Name | Severity | Fix? |
|---|---|---|---|
| THR001 | Unhandled Result | Warning | No |
| THR003 | Result<T> creation not assigned | Info | No |
| THR006 | Unchecked Error access | Warning | No |
| THR300 | Missing failure branch | Warning | No |
| THR306 | Discarded Error in Match | Warning | No |
| THR060 | Combine over Bind staircase | Info | Yes |
| THR061 | Combine over sequential guards | Info | Yes |
| THR062 | Destructured lambda | Info | Yes |
| THR069 | TrySelect over loop | Info | Yes |
| THR070 | OrElse over fallback pattern | Info | Yes |
| THR071 | Combine over tuple assembly | Info | Yes |
Documentation
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Throwaway.Core:
| Package | Downloads |
|---|---|
|
Throwaway.TestHelpers
Test helper utilities for the Throwaway Result pattern library |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 100 | 3/21/2026 |