Fix a bug in update and generalize the 'check' predicate to be a simple shorthand to bind the box into something

This commit is contained in:
Tissevert 2021-01-15 11:11:26 +01:00
parent 0ff9052a81
commit 7c8b4a3b87

View file

@ -15,15 +15,15 @@ Box.prototype.set = function(newValue) {
}.bind(this); }.bind(this);
}; };
Box.prototype.check = function(predicate) { Box.prototype.bind = function(f) {
return function(f) { return function(g) {
predicate(this.value)(f); f(this.value)(g);
} }.bind(this);
}; };
Box.prototype.update = function(modifier) { Box.prototype.update = function(modifier) {
return function(f) { return function(f) {
modifier(this.value)(function (newValue) {this.value = newValue; f()}); modifier(this.value)(function (newValue) {this.value = newValue; f()}.bind(this));
}.bind(this); }.bind(this);
}; };
@ -36,7 +36,7 @@ function make(initValue) {
return { return {
get: box.get.bind(box), get: box.get.bind(box),
set: box.set.bind(box), set: box.set.bind(box),
check: box.check.bind(box), bind: box.bind.bind(box),
update: box.update.bind(box), update: box.update.bind(box),
}; };
} }