expect method
Unwraps the success value, or throws an exception with message.
Use this when you're certain the result should be Ok, but want to provide a custom error message if it's not. The original stack trace is preserved. For unwrapping with fallback values, use unwrapOr or unwrapOrElse instead.
Example:
final value = result.expect('Operation should have succeeded');
final config = loadConfig().expect('Config file must be valid');
Implementation
T expect(String message) => switch (this) {
Ok(:final value) => value,
Err(:final stackTrace) => Error.throwWithStackTrace(
Exception(message),
stackTrace,
),
};