ambjs
Version:
amb(iguous) operator in javascript
59 lines • 1.92 kB
JavaScript
var trampoline$727 = require('./trampoline');
var Expression$728 = function (fn$735) {
this.eval = fn$735;
};
var succ$729 = function (v$736, fail$737) {
return {
value: v$736,
next: fail$737
};
};
var fail$730 = function () {
throw new Error('Impossible!');
};
var default_options$731 = {
ids: false,
increment: 2,
limit: 32,
succ: succ$729,
fail: fail$730
};
var merge$732 = function (as$738) {
var result$739 = {};
as$738.forEach(function (a$740) {
if (a$740)
for (var j$741 in a$740)
result$739[j$741] = a$740[j$741];
});
return result$739;
};
Expression$728.prototype.run = function (opts$742) {
var options$743 = merge$732([
default_options$731,
opts$742
]), self$744 = this, ids$745 = options$743.ids, limit$746 = options$743.limit, increment$747 = options$743.increment, succ$748 = function (v$750, fail$751, ff$752) {
return options$743.succ(v$750, fail$751);
}, fail$749 = function () {
if (!ids$745)
return options$743.fail();
limit$746 += increment$747;
return self$744.eval(succ$748, fail$749, limit$746).run();
};
return this.eval(succ$748, fail$749, ids$745 ? limit$746 : undefined).run();
};
var bind$733 = function (e$753, next$754) {
return expression$734(function (succ$755, fail$756, ff$757) {
return e$753.eval(function (v$758, _fail$759, _ff$760) {
return trampoline$727(function () {
return next$754(v$758).eval(succ$755, _fail$759, _ff$760);
});
}, fail$756, ff$757);
});
};
Expression$728.prototype.bind = function (next$761) {
return bind$733(this, next$761);
};
var expression$734 = function (fn$762) {
return new Expression$728(fn$762);
};
module.exports = expression$734;