Transforms the value inside a Maybe structure with an unary function. Only
transforms values that are successful (Just
), and constructs a new Maybe as a
result.
forall a, b: (Maybe a).((a) => b) => Maybe b
Transforms the value inside a Maybe structure with an unary function. Only
transforms values that are successful (Just
), and constructs a new Maybe as a
result.
const Maybe = require('folktale/maybe');
function increment(value) {
return value + 1;
}
Maybe.Just(1).map(increment);
// ==> Maybe.Just(2)
Maybe.Nothing().map(increment);
// ==> Maybe.Nothing()
{
/*~*/
Nothing: function map(transformation) {
assertFunction('Maybe.Nothing#map', transformation);
return this;
},
/*~*/
Just: function map(transformation) {
assertFunction('Maybe.Just#map', transformation);
return Just(transformation(this.value));
}
}