replacePossibleError method

Result<T> replacePossibleError(
  1. Error oldErrorReplacer(
    1. Error oldErr
    )
)

If the Result is a Err, then replaces internal err with result if given function oldErrorReplacer. Function oldErrorReplacer should take old error and return new error; And returns changed result; If the Result is a Ok, then return unchanged Result as is;

Implementation

Result<T> replacePossibleError(
    Error Function(Error oldErr) oldErrorReplacer) {
  if (isErr) {
    return Err(oldErrorReplacer(_err!));
  }
  return this;
}