mapErr
ts
function Result.mapErr(
result: Result<T, E>,
transform: (error: E) => F
): Result<T, F>Transforms the Err value using the transform function. If the result is an Err, applies the transform function to the error value and returns a new Err. If the result is Ok, returns it unchanged.
Example
ts
Result.mapErr(err("fail"), (e) => `Error: ${e}`);
// Err<string>("Error: fail")
Result.mapErr(ok(5), (e) => `Error: ${e}`);
// Ok<number>(5)ts
pipe(
err("fail"),
Result.mapErr((e) => `Error: ${e}`),
);
// Err<string>("Error: fail")