ResTOr Method

Overload List

Or(FuncResT) (lazy version) Combines two results: this and other as follows:
  • returns this if this is Ok;
  • returns other otherwise.

In other words, this is a flattened alternative to UnwrapOr(T).

C#
var or = Ok(42).Or(Ok(7));
Assert.Equal(Ok(42), or);

or = Ok(42).Or(Err<int>("error-message"));
Assert.Equal(Ok(42), or);

or = Err<int>("error-message").Or(Ok(7));
Assert.Equal(Ok(7), or);

or = Err<int>("error-message").Or(Err<int>("second-error-message"));
Assert.True(or.IsErr);
Assert.Equal(Some("second-error-message"), or.ErrorMessage());
Or(ResT) Combines two results: this and other as follows:
  • returns this if this is Ok;
  • returns other otherwise.

In other words, this is a flattened alternative to UnwrapOr(T).

C#
var or = Ok(42).Or(Ok(7));
Assert.Equal(Ok(42), or);

or = Ok(42).Or(Err<int>("error-message"));
Assert.Equal(Ok(42), or);

or = Err<int>("error-message").Or(Ok(7));
Assert.Equal(Ok(7), or);

or = Err<int>("error-message").Or(Err<int>("second-error-message"));
Assert.True(or.IsErr);
Assert.Equal(Some("second-error-message"), or.ErrorMessage());

See Also