mapErr<F extends Object> method
Transforms the error value using block, leaving success values unchanged.
If this is Err, applies block to the error and wraps the result in
a new error type. If this is Ok, returns the same success value with
the new error type. Useful for converting error types when delegating
to functions expecting different error types.
Example:
Result<String, String> result = Err('failed');
final mapped = result.mapErr((e) => CustomError(e)); // Err(CustomError)
Implementation
Result<T, F> mapErr<F extends Object>(F Function(E error) block) =>
switch (this) {
Err<T, E>(:final error, :final stackTrace) => .err(
block(error),
stackTrace,
),
Ok<T, E>(:final value) => .ok(value),
};