For the complete documentation index, see llms.txt. This page is also available as Markdown.

Quickstart

Ready to eliminate null checks and stop catching exceptions? Here's how to get up and running with Waystone.Monads.

Installation

Install via the dotnet CLI:

dotnet add package Waystone.Monads

Using Option<T>

The Option<T> type represents a value that may or may not be present. It eliminates the ambiguity and risks of null , and provides a way to mark a value as intentionally absent.

Option<string> name = Option.Some("Liam O'Brian");
Option<string> missing = Option.None<string>();

string greeting = name.Match(
    some => $"Hello, {some}!",
    () => "Hello, stranger!"
);

// Output: "Hello, Liam O'Brian!"

Use Map, Inspect, Match, and more to work with values safely and fluently

Using Result<T, E>

The Result<T, E> type represents a success or failure as a value instead of throwing exceptions. It allows you to reserve exceptions for exceptional scenarios, and provides a framework for handling success and failure outcomes explicitly. Use it instead of throwing exceptions for recoverable failures.

Last updated

Was this helpful?