was.js
/trunk/lib/lambda/aggregators.js/aggregators.js |
@@ -3,19 +3,18 @@ |
/*************************************************************************/ |
/* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */ |
/*************************************************************************/ |
// Vanilla ES6 JavaScript |
function wasSwitch(q, d, ...c) { |
if(c.length % 2 !== 0) { |
function wasSwitch() { |
if(arguments.length % 2 !== 0) { |
throw "Pairs of predicates expected for cases"; |
} |
|
(Array.isArray(q) ? q : [ q ]).forEach((s) => { |
(Array.isArray(arguments[0]) ? arguments[0] : [ arguments[0] ]).forEach((s) => { |
var m = false; |
for(var i = 0; i < c.length; i += 2) { |
if(!c[i](s)) { |
for(var i = 2; i < arguments.length; i += 2) { |
if(!arguments[i](s)) { |
continue; |
} |
if(!c[i + 1](s)) { |
if(!arguments[i + 1](s)) { |
continue; |
} |
m = true; |
@@ -22,13 +21,13 @@ |
} |
|
if(!m) { |
d(s); |
arguments[1](s); |
} |
}); |
} |
if (!Array.prototype.switch) { |
Array.prototype.switch = function(d, ...c) { |
wasSwitch(this, d, ...c); |
Array.prototype.switch = function() { |
wasSwitch(this, arguments[0], arguments.slice(1)); |
}; |
} |
// jQuery |