unwrap method

  1. @override
  2. @useResult
Never unwrap({
  1. String? msg,
})
override

Returns the contained value.

Throws

Throws a StateError (with custom message msg if provided) if this is an Err.

Examples

// prints "2"
print(const Ok<int, String>(2).unwrap());

// throws a `StateError`
print(const Err<int, String>('error').unwrap());

Implementation

@override
@useResult
Never unwrap({String? msg}) {
  throw StateError('${msg ?? 'tried to unwrap `Err` as `Ok`'}: $error');
}