Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bmtlab/stateresults
A redesigned version of the Unions functional paradigm, inspired by the OneOf package
https://github.com/bmtlab/stateresults
csharp discriminated-unions oneof results state unions
Last synced: about 1 month ago
JSON representation
A redesigned version of the Unions functional paradigm, inspired by the OneOf package
- Host: GitHub
- URL: https://github.com/bmtlab/stateresults
- Owner: BMTLab
- License: other
- Created: 2023-08-10T17:17:47.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-25T11:47:26.000Z (9 months ago)
- Last Synced: 2024-10-29T21:32:26.456Z (2 months ago)
- Topics: csharp, discriminated-unions, oneof, results, state, unions
- Language: C#
- Homepage:
- Size: 118 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# BMTLab.StateResults
[![NuGet](https://img.shields.io/nuget/v/BMTLab.StateResults?logo=nuget)](https://www.nuget.org/packages/BMTLab.StateResults)
![Nuget Downloads](https://img.shields.io/nuget/dt/BMTLab.StateResults)
![.NET](https://github.com/BMTLab/StateResults/workflows/publish/badge.svg)## OneOf.Reduced & StateResults - .NET 8 Discriminated Type Unions Library
This library introduces a powerful mechanism for discriminated type unions in .NET 8 through two main constructs: OneOf and Result/Results.
Both these constructs can work with up to 6 type arguments (T0, T1, ... T5).## How to Use
### OneOf.Reduced
The core concept of the library. Represents a choice between one of the given types.1. Basic usage
```csharp
OneOf union;union = "Operation is successful";
Console.WriteLine(union); // >> Operation is successfulunion = 42;
Console.WriteLine(union); // >> 42
```2. Equality Check
```csharp
OneOf unionA = 42;
OneOf unionB = 42;bool isMatch = unionA == unionB;
Console.WriteLine(isMatch); // >> True
```3. Matching Values
```csharp
OneOf union = "Some text";string result = union.Match
(
number => number.ToString(),
text => text.ToUpperInvariant(),
error => error.Message
);Console.WriteLine(result); // >> SOME TEXT
```