Transforms the value inside an Error without changing the context of the computation.
forall a, b, c:
(Result a b).((a) => c) => Result c b
Transforms the value inside an Error without changing the context of the computation.
This is similar to .map
, except it operates on Errors instead of Oks.
const Result = require('folktale/result');
Result.Error(1).mapError(x => x + 1);
// ==> Result.Error(2)
Result.Ok(1).mapError(x => x + 1);
// ==> Result.Ok(1)
{
/*~*/
Error: function mapError(f) {
assertFunction('Result.Error#mapError', f);
return Error(f(this.value));
},
/*~*/
Ok: function mapError(f) {
assertFunction('Result.Ok#mapError', f);
return this;
}
}