unwrap method

S unwrap()

Unwraps the Result and returns the Success value.

If the result is a Success, returns the success value. If the result is a Failure, throws an exception.

Use this method when you are certain that the result is a success and you want to access the Success value directly.

Example usage:

final result = await someAsyncOperation();

final value = result.unwrap();
print('Success value: $value');

Implementation

S unwrap() {
  if (isSuccess) {
    return _left.value;
  } else {
    throw Exception('Cannot unwrap a failure result. \n$_right');
  }
}