Transforms each side of a Result with a function, without changing the context of the computation. That is, Errors will still be Errors, Oks will still be Oks.
(Result a b).((a) => c, (b) => d) => Result c d
Transforms each side of a Result with a function, without changing the context of the computation. That is, Errors will still be Errors, Oks will still be Oks.
const Result = require('folktale/result');
const inc = (x) => x + 1;
const dec = (x) => x - 1;
Result.Ok(1).bimap(inc, dec);
// ==> Result.Ok(dec(1))
Result.Error(1).bimap(inc, dec);
// ==> Result.Error(inc(1))
{
/*~*/
Error: function bimap(f, g) {
assertFunction('Result.Error#bimap', f);
assertFunction('Result.Error#bimap', g);
return Error(f(this.value));
},
/*~*/
Ok: function bimap(f, g) {
assertFunction('Result.Ok#bimap', f);
assertFunction('Result.Ok#bimap', g);
return Ok(g(this.value));
}
}