mapError<F> method

Expected<T, F> mapError<F>(
  1. F mapper(
    1. E error
    )
)

Transforms the error value of type E into a new error of type F using the provided mapper function.

If this object contains a value, the value is passed along unmodified.

Implementation

Expected<T, F> mapError<F>(F Function(E error) mapper) {
  if (!_hasValue) {
    return Expected<T, F>.error(mapper(_error as E));
  } else {
    return Expected<T, F>.value(_value as T);
  }
}