Transforms the value inside of a Result structure with an unary function without
changing the context of the computation. That is, Error
values continue to be
Error
values, and Ok
values continue to be Ok
values.
This API is still experimental, so it may change or be removed in future versions. You should not rely on it for production applications.
forall a, b, c:
(Result a b).((b) => c) => Result a c
Transforms the value inside of a Result structure with an unary function without
changing the context of the computation. That is, Error
values continue to be
Error
values, and Ok
values continue to be Ok
values.
const Result = require('folktale/result');
function increment(value) {
return value + 1;
}
Result.Ok(1).map(increment);
// ==> Result.Ok(2)
Result.Error(1).map(increment);
// ==> Result.Error(1)
{
/*~*/
Error: function map(f) {
assertFunction('Result.Error#map', f);
return this;
},
/*~*/
Ok: function map(f) {
assertFunction('Result.Ok#map', f);
return Ok(f(this.value));
}
}