inspectErr method
Executes a side effect if this is an error, then returns this unchanged.
The block callback is invoked with the error value if this is Err.
The result is returned unchanged, allowing for method chaining. Useful
for logging errors, metrics, or cleanup without consuming the result.
Does nothing if this is Ok.
Example:
result
.inspectErr((e) => logger.error('Failed: $e'))
.inspectErr((e) => metrics.recordError(e))
.unwrapOr(defaultValue);
Implementation
Result<T, E> inspectErr(void Function(E error) block) {
if (this case Err(:final error)) {
block(error);
}
return this;
}