mapErr<F> method

  1. @override
Result<T, F> mapErr<F>(
  1. F errMap(
    1. E error
    )
)
override

Maps a Result<T, E> to Result<T, F> by applying a function to a contained Err (failure) value, leaving an Ok (success) value untouched.

This function can be used to pass through a successful result while handling an error.

Examples

Basic usage:

String stringify(int x) => 'error code: $x';

Result<int, int> x = Ok(2);
expect(x.mapErr(stringify), Ok<int, String>(2));

Result<int, int> y = Err(13);
expect(y.mapErr(stringify), Errint, String>('error code: 13'));

Implementation

@override
Result<T, F> mapErr<F>(F Function(E error) errMap) {
  return Err(errMap(e));
}