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

Consume

Methods that end the chain and hand you a plain value.

Everything on this page takes you out of the Result. To keep chaining, see Transform.

IsOk and IsErr

bool IsOk { get; }
bool IsErr { get; }

The state, as a bool. Properties, not methods.

Result<DateTime, Error> safeParseResult = SafeParse("2025-01-01");

safeParseResult.IsOk;  // true
safeParseResult.IsErr; // false

Good for a short-circuit or a guard. Reach for Match when both branches matter.

IsOkAnd

bool IsOkAnd(Predicate<TOk> predicate)

It succeeded and the value passes the predicate.

safeParseResult.IsOkAnd(dateTime => dateTime > new DateTime(2024, 1, 1)); // true

IsErrAnd

bool IsErrAnd(Predicate<TErr> predicate)

It failed and the error passes the predicate.

Match

Both branches, one plain value out. This is the default way to end a chain.

On an Err: length is 0 — the onErr branch runs and onOk does not.

Match also has the state overload that saves the most. See Match saves the most.

Pattern matching with Deconstruct

From 7.0.0 the case types deconstruct, so C# pattern matching binds either side positionally.

The full list of Deconstruct methods, and why a switch expression still warns, is on the Option page. Both types behave the same way.

Unlike Option, both of a Result's cases deconstruct, because both carry a value.

Unwrap

The success value, or a throw.

On an Err: throws UnwrapException.

An intentional point of failure, like First on an empty sequence. Otherwise reach for Match.

UnwrapErr

The other direction. The error, or a throw.

On an Ok: throws UnwrapException.

UnwrapOr

The success value, or the fallback you already have.

UnwrapOrElse

The same, but the factory runs only on an Err — and it receives the error, so the fallback can depend on what went wrong.

UnwrapOrDefault

The success value, or default(TOk).

UnwrapOrNull

The success value, or null — a real Nullable<TOk>, so failure stays visible. An extension method, in Waystone.Monads.Results.Extensions.

Constrained to TOk : struct. A reference type needs no equivalent — UnwrapOrDefault already gives null.

Expect

Like Unwrap, but you supply the message the exception carries.

On an Err: throws UnmetExpectationException carrying your message.

ExpectErr

The other direction, and the same idea.

On an Ok: throws UnmetExpectationException carrying your message.

MapOr

Transforms the success value, or returns your fallback. Unlike Map, it ends the chain.

MapOrElse

The same, building the fallback from the error.

Its state overload threads the same state through both delegates — see MapOrElse threads state through both delegates.

MapOrDefault

The same, falling back to default(TOut).

MapOrNull

The same, falling back to null. This one is on Result<TOk, TErr> itself, so it needs no extra using — unlike UnwrapOrNull, which is an extension.

Last updated

Was this helpful?