mapFailure method
Transforms the inner Failure details if the operational outcome is a failure state.
If the current Result is a success, the conversion step is short-circuited and the original SuccessResult passes through untouched.
Example:
final uiResult = apiResult.mapFailure(
(fail) => Failure(message: 'Localized Error: ${fail.message}')
);
Implementation
Result<S> mapFailure(Failure Function(Failure failure) transform) {
return switch (this) {
SuccessResult<S>() => this,
FailureResult<S>(failure: final failure) =>
Result.failure(transform(failure)),
};
}