Map over a Ok
, exactly as in map
, but operating on the
value wrapped in an Err
instead of the value wrapped in the
Ok
. This is handy for when you need to line up a bunch of
different types of errors, or if you need an error of one shape to be in a
different shape to use somewhere else in your codebase.
import { ok, err, mapErr, toString } from 'true-myth/result';
const reason = (err: { code: number, reason: string }) => err.reason;
const anOk = ok(12);
const mappedOk = mapErr(reason, anOk);
console.log(toString(mappedOk)); // Ok(12)
const anErr = err({ code: 101, reason: 'bad file' });
const mappedErr = mapErr(reason, anErr);
console.log(toString(mappedErr)); // Err(bad file)
Map over a
Ok
, exactly as inmap
, but operating on the value wrapped in anErr
instead of the value wrapped in theOk
. This is handy for when you need to line up a bunch of different types of errors, or if you need an error of one shape to be in a different shape to use somewhere else in your codebase.Examples