was.js

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 13  →  ?path2? @ 14
/trunk/lib/lambda/aggregators.js
@@ -0,0 +1,51 @@
/*************************************************************************/
/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */
/*************************************************************************/
/* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */
/*************************************************************************/
if (!Array.prototype.switch) {
Array.prototype.switch = function(d, c) {
if(c.length % 2 != 0)
throw "Pairs of predicates expected for cases";
this.forEach((s) => {
var m = false;
for(i = 0; i < c.length; i += 2) {
if(!c[i](s))
continue;
if(!c[i + 1](s))
continue;
m = true;
}
if(!m)
d(s)
});
};
}
 
/*************************************************************************/
/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */
/*************************************************************************/
/* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */
/*************************************************************************/
$.extend({
switch: function(q, d, c) {
if(c.length % 2 != 0)
throw "Pairs of predicates expected for cases";
q.forEach((s) => {
var m = false;
for(i = 0; i < c.length; i += 2) {
if(!c[i](s))
continue;
if(!c[i + 1](s))
continue;
m = true;
}
if(!m)
d(s)
});
}
});