A new Result<UnwrapOk<R>, E2>
.
const okValue = Result.ok(3) as Result<number, string>;
const errValue = Result.err('missing');
const untouchedOk = Result.mapErr(okValue, (error) => error.toUpperCase());
const uppercasedErr = Result.mapErr(errValue, (error) => error.toUpperCase());
assert.deepStrictEqual(untouchedOk, Result.ok(3));
assert.deepStrictEqual(uppercasedErr, Result.err('MISSING'));
const mapError = Result.mapErr((error: Readonly<Error>) => error.message);
const wrapped = mapError(Result.err(new Error('boom')));
assert.deepStrictEqual(wrapped, Result.err('boom'));
Maps a Result<S, E>
to Result<S, E2>
by applying a function to the
error value. If the Result
is Result.Ok
, returns the original Ok
.
The type of the error value returned by the mapping function.
A new Result<UnwrapOk<R>, E2>
.
const okValue = Result.ok(3) as Result<number, string>;
const errValue = Result.err('missing');
const untouchedOk = Result.mapErr(okValue, (error) => error.toUpperCase());
const uppercasedErr = Result.mapErr(errValue, (error) => error.toUpperCase());
assert.deepStrictEqual(untouchedOk, Result.ok(3));
assert.deepStrictEqual(uppercasedErr, Result.err('MISSING'));
const mapError = Result.mapErr((error: Readonly<Error>) => error.message);
const wrapped = mapError(Result.err(new Error('boom')));
assert.deepStrictEqual(wrapped, Result.err('boom'));
Maps a
Result<S, E>
toResult<S, E2>
by applying a function to the error value. If theResult
isResult.Ok
, returns the originalOk
.