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

Welcome

Keep exceptions exceptional

Waystone.Monads gives C# two types that say what your code actually means.

  • Option<T> — the value might not be there.

  • Result<T, E> — the work might fail.

Both are ordinary C# types. There is no framework to adopt and nothing to wire up. You add a package, you change a return type, and the compiler starts telling you about the cases you used to find at runtime.

Who this is for

You are writing C# and you are tired of two things: null reaching places it should not, and exceptions being used for outcomes that are not exceptional.

The library replaces both with values you can return, pass around, and compose. Absence and failure stop being surprises hidden inside a method body, and start being part of the signature you already read.

If you have used Option and Result in Rust or F#, you already know the shape. If you have not, Why monads walks through it with no prior knowledge assumed.

Where to go next

If you want to
Go to

Install the package and see both types work

Understand why this beats null and try/catch

Teach your coding agent to write it properly

What comes in the box

Installing Waystone.Monads gets you the two types, a Roslyn analyzer, and a source generator. You configure none of it. The analyzer flags the mistakes people make with these types, and the generator turns an enum into a set of error codes. See Analyzer rules and Generated error codes.

Optional packages sit beside the library — Shouldly assertions, LINQ query syntax, JSON converters, and more. None is required, and none changes how Waystone.Monads behaves. Add-ons extend the library itself. Integrations connect it to a library you already use.

Last updated

Was this helpful?