unwrapOrElse method
T
unwrapOrElse(
- T block(
- E error
Returns the success value, or computes a default from the error.
Applies block to the error to compute a fallback value if this is Err.
Use this when the default value depends on what the error was, allowing
context-aware recovery. For static defaults, use unwrapOr instead.
Example:
final value = result.unwrapOrElse(
(e) => handleError(e),
);
final retryCount = result.unwrapOrElse(
(e) => e.isRetryable ? 3 : 0,
);
Implementation
T unwrapOrElse(T Function(E error) block) => switch (this) {
Ok(:final value) => value,
Err(:final error) => block(error),
};