When working with partial mapping function (not every possible input is valid), I ended up making a small helper:
function strictMap(property, f) {
return property.withHandler(function (ev) {
try {
var x = ev.fmap(f);
// force
if (x.hasValue()) {
x.value();
}
return this.push(x);
} catch (err) {
return this.push(new Bacon.Error(err));
}
});
}
With this helper I can use strictMap(property, myMapper)
in the same fashion as property.map(myMapper)
. Is such functionality already in Bacon.js somewhere, or am I doing something in a wrong way?
Compare to Observable.map which doesn't catch anything?