unwrapOrElse method
T
unwrapOrElse(
- T fallback(
- E error
Returns the successful value, or computes one from the error.
fallback is not called for an Ok.
final count = const Err<int, String>('invalid')
.unwrapOrElse((error) => error.length);
final existing = const Ok<int, String>(7)
.unwrapOrElse((error) => error.length);
Implementation
T unwrapOrElse(T Function(E error) fallback) {
return switch (this) {
Ok<T, E>(:final value) => value,
Err<T, E>(:final error) => fallback(error),
};
}