ResTUnwrapOr Method

Overload List

UnwrapOr(FuncT) Returns the underlying value when IsOk; or returns lazyFallbackValue() when IsErr. This is a safe way to unwrap the result, by explicitly handling the Err variant. Use the eager UnwrapOr(T) variant if the fallback value is cheap or readily available.
C#
static string ParseUserTablename(..) { /*parses the table name from command line input; might throw!*/ }
static string QueryUserTablename(..) { /*makes an expensive db-call to find out the table name*/ }

string userTable = Ok()                                         // Res, certainly Ok
                    .TryMap(() => ParseUserTablename(..))       // Res<string>: might be Err if parser throws
                    .UnwrapOr(() => QueryUserTablename(..));    // directly returns ParseUserTablename's result if it is Ok;
                                                                // calls QueryUserTablename otherwise and returns its result.
UnwrapOr(T) Returns the underlying value when IsOk; or returns the fallbackValue when IsErr. This is a safe way to unwrap the result, by explicitly handling the Err variant. Use the lazy UnwrapOr(FuncT) variant if the computation of the fallback value is expensive.
C#
Assert(Ok(42).UnwrapOr(7) == 42);
Assert(Err<int>("error-message").UnwrapOr(7) == 7);

See Also