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; // falseIsOkAnd
bool IsOkAnd(Predicate<TOk> predicate)It succeeded and the value passes the predicate.
safeParseResult.IsOkAnd(dateTime => dateTime > new DateTime(2024, 1, 1)); // trueIsErrAnd
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.
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).
On a value type this is the catch. The signature reads TOk?, but TOk is constrained notnull, so the ? is an annotation rather than a Nullable<TOk>. UnwrapOrDefault on a Result<int, string> hands you 0, and nothing tells you whether that 0 came from an Ok or from the failure. Reach for UnwrapOrNull there. WM2015 points this out for you.
UnwrapOrNull
The success value, or null — a real Nullable<TOk>, so failure stays visible. An extension method, in Waystone.Monads.Results.Extensions.
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).
The signature reads TOut?, but TOut is constrained notnull, so on a value type that ? is an annotation and not a Nullable<TOut>. Map to an int and the failure case gives you 0, not null.
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?