mapErr<E2 extends Exception> method

Result<T, E2> mapErr<E2 extends Exception>(
  1. E2 onErr(
    1. E
    )
)

Maps the error from E to E2 if it is Err, else, keeps the Ok, T.

Implementation

Result<T, E2> mapErr<E2 extends Exception>(E2 Function(E) onErr) {
  return switch (this) {
    Ok(:final T value) => Ok(value),
    Err(:final E err) => Err(onErr(err)),
  };
}