Info
Version: | 0.3.0 |
Author(s): | Sebastian Öberg |
Last Update: | Thursday, February 20, 2025 |
.NET Fiddle: | Create the first Fiddle |
Project Url: | https://github.com/bazer/ThrowAway |
NuGet Url: | https://www.nuget.org/packages/ThrowAway |
Install
Install-Package ThrowAway
dotnet add package ThrowAway
paket add ThrowAway
ThrowAway Download (Unzip the "nupkg" after downloading)
**ThrowAway** is a pragmatic and efficient C# library that marries functional programming concepts with traditional procedural error handling.
It is designed to elegantly manage the dichotomy between successful outcomes (`Values`) and error states (`Failures`) by leveraging the power of the **Option** type. This hybrid approach makes it easy to write expressive, functional code while still integrating seamlessly with conventional try-catch exception handling.
## Overview
In many C# applications, error handling is either bogged down by traditional exception logic or forced into a rigid functional style. ThrowAway bridges these two worlds by offering:
- **Explicit Functional Handling:** Model success and failure as first-class citizens with Option types.
- **Seamless Procedural Integration:** Implicit conversions let you work with Options as if they were plain values - while automatically throwing a `HasFailedException` when an Option is in a failed state. This allows you to mix functional transformations with traditional try-catch error management.
## Key Features
- **Dual Outcomes:** Every operation returns an Option that encapsulates either a valid result (`Value`) or an error (`Failure`).
- **Implicit Conversions:** Options automatically convert to their underlying type.
When an Option represents a failure, an exception is thrown, enabling smooth integration with procedural exception handling.
- **Rich Functional API:** A suite of extension methods (like `Map`, `FlatMap`, `Match`, `Filter`, `Transpose`, and `Use`) enables chaining and composing operations in a functional style.
- **No Nulls:** Being struct-based, Options guarantee non-null instances, improving type safety.
- **Hybrid Error Handling:** Combines the explicitness of functional error handling with the convenience of procedural exception handling.
- **Robust Exception Wrapping:** Methods like `CatchFailure` and `CatchAll` convert exceptions into failed Options, maintaining consistency in error handling.
- **Seamless Unwrapping:** `TryUnwrap` lets you extract both the value and the failure message without additional boilerplate.