Constellations/js/Solver/Strategy.js

32 lines
536 B
JavaScript
Raw Normal View History

2022-08-19 08:19:50 +02:00
return {
execute: execute,
tryEach: tryEach,
map: map
}
function tryEach(strategies) {
return function() {
for(var i = 0; i < strategies.length; i++) {
var result = strategies[i]();
if(result != undefined) {
return result;
}
}
};
}
function execute(strategy, onSuccess, onError) {
var result = strategy();
if(result != undefined) {
return onSuccess(result);
} else {
return onError(result);
}
}
function map(f, strategy) {
return function() {
return execute(strategy, f, function() {return;});
};
}