Danom
Option, Result and Choice types for C# to simplify functional programming.
Install / Use
/learn @pimbrouwers/DanomREADME

Danom provides Option, Result and Choice types for C#, inspired by F#. It’s designed to be easy to use, efficient, and compatible with existing C# codebases. These discriminated unions offer a type-safe way to represent nullable values, expected errors and decisions, while also supporting a fluent API (e.g., map, bind) for chaining operations and value transformations.
using Danom;
// Option: Represent nullable values safely
Option.Some(5)
.Map(x => x * 2)
.Match(
some: x => Console.WriteLine($"Value: {x}"),
none: () => Console.WriteLine("No value"));
// ^-- Output: Value: 10
// Result: Handle success or error outcomes
Result<int, string>.Ok(10)
.Map(x => x + 1)
.Match(
ok: x => Console.WriteLine($"Result: {x}"),
error: e => Console.WriteLine($"Error: {e}"));
// ^-- Output: Result: 11
// Choice: Represent one of multiple types
Choice<int, string, double>.FromT2("Hello")
.Match(
t1: x => Console.WriteLine($"Got int: {x}"),
t2: s => Console.WriteLine($"Got string: {s}"),
t3: d => Console.WriteLine($"Got double: {d}"));
// ^-- Output: Got string: Hello
Key Features
- Implementation of common monads: Option, Result and Choice.
- Exhaustive matching to prevent null reference exceptions.
- Fluent API for chaining operations, including async support.
- Built-in error handling with ResultErrors.
- An API for parsing strings into .NET primitives and value types.
- Unit type to represent the absence of a value.
- Input validation via Danom.Validation.
- Integrations with ASP.NET MVC and ASP.NET Minimal API.
Design Goals
netstandard2.1compatible.- Simplify and enhance functional programming in C#.
- Support both synchronous and asynchronous operations.
- Provide opionated monads to encourage consistent use.
Getting Started
Install the Danom NuGet package:
dotnet add package Danom
OR
PM> Install-Package Danom
Documentation for Danom can be found here.
Looking for Validation or ASP.NET Core Integration?
- Get started with Danom.Validation
- Get started with Danom.MinimalApi
- Get started with Danom.Mvc
Input Validation
One of the places the Result type really shines is input validation. It's a natural step in most workflows to validate input data before processing it, and the Result type is a great way to handle this. The Danom.Validation library provides an API for defining validation rules and checking input data against those rules, returning a Result<T, ResultErrors> that contains either the validated data or an error message.
Integrations
Since Danom introduces types that are most commonly found in your model and domain layers, external integrations are not only inevitable but required to provide a seamless experience when building applications.
These are completely optional, but provide a great way to integrate Danom with your codebase.
ASP.NET Core MVC & Razor Pages Integration
Danom is integrated with ASP.NET Core MVC (and Razor Pages) via Danom.Mvc. This library provides extension methods and a base controller to help integrate the core types with common tasks in ASP.NET Core MVC applications.
ASP.NET Core Minimal API Integration
Danom is integrated with ASP.NET Core Minimal API via Danom.MinimalApi. This library provides a set of utilities to help integrate the core types with common tasks in ASP.NET Core Minimal API applications.
Changelog
All notable changes to this project will be documented in these files:
- Danom CHANGELOG - Core library changelog.
- Danom.Validation CHANGELOG - Validation library changelog.
- Danom.Mvc CHANGELOG - MVC integration changelog.
- Danom.MinimalApi CHANGELOG - Minimal API integration changelog.
Contributing
I kindly ask that before submitting a pull request, you first submit an issue.
If functionality is added to the API, or changed, please kindly update the relevant documentation. Unit tests must also be added and/or updated before a pull request can be successfully merged.
Only pull requests which pass all build checks and comply with the general coding standard can be approved.
Find a bug?
There's an issue for that.
License
Licensed under MIT.
Related Skills
node-connect
337.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.3kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
337.7kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.3kCommit, push, and open a PR
