unwrap method

T unwrap()

Returns the successful value, or throws for an Err.

Throws a StateError naming the error. Prefer expect where the reason the operation cannot fail is worth saying, and a switch or unwrapOr wherever it can.

final id = const Ok<int, String>(7).unwrap(); // 7

Implementation

T unwrap() {
  return switch (this) {
    Ok<T, E>(:final value) => value,
    Err<T, E>(:final error) =>
      throw StateError('called unwrap() on Err: $error'),
  };
}