expect method

  1. @override
T expect(
  1. String message
)
override

Returns the contained Ok (success) value.

Throws an exception

Throws an exception if the value is an Err (failure), with an exception message including the passed message, and the content of the Err.

Examples

Basic usage:

Result<int, String> x = Err("emergency failure");
x.expect("Testing expect"); // Throws an exception with message `Testing expect: emergency failure`

Result<int, String> y = Ok(5);
print(y.expect("Should print `5`")); // 5

Implementation

@override
T expect(String message) {
  return v;
}