was.js

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 21  →  ?path2? @ 22
/trunk/lib/lambda/aggregators.js
@@ -3,63 +3,12 @@
/*************************************************************************/
/* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */
/*************************************************************************/
// Vanilla ES6 JavaScript
if (!Array.prototype.switch) {
Array.prototype.switch = function(d, ...c) {
if(c.length % 2 !== 0) {
throw "Pairs of predicates expected for cases";
}
(Array.isArray(this) ? this : [ this ]).forEach((s) => {
var m = false;
for(var i = 0; i < c.length; i += 2) {
if(!c[i](s)) {
continue;
}
if(!c[i + 1](s)) {
continue;
}
m = true;
}
if(!m) {
d(s);
}
});
};
}
// jQuery
$.extend({
switch: function(q, d, ...c) {
if(c.length % 2 !== 0) {
throw "Pairs of predicates expected for cases";
}
(Array.isArray(q) ? q : [ q ]).forEach((s) => {
var m = false;
for(var i = 0; i < c.length; i += 2) {
if(!c[i](s)) {
continue;
}
if(!c[i + 1](s)) {
continue;
}
m = true;
}
if(!m) {
d(s);
}
});
}
});
// Node.JS
module.exports.switch = function(q, d, ...c) {
function wasSwitch(q, d, ...c) {
if(c.length % 2 !== 0) {
throw "Pairs of predicates expected for cases";
}
(Array.isArray(q) ? q : [ q ]).forEach((s) => {
(Array.isArray(this) ? this : [ this ]).forEach((s) => {
var m = false;
for(var i = 0; i < c.length; i += 2) {
if(!c[i](s)) {
@@ -75,4 +24,17 @@
d(s);
}
});
}
 
// Vanilla ES6 JavaScript
if (!Array.prototype.switch) {
Array.prototype.switch = wasSwitch;
}
// jQuery
$.extend({
switch: wasSwitch
});
// Node.JS
module.exports = {
switch: wasSwitch
};
/trunk/package.json
@@ -13,7 +13,7 @@
"name": "was.js",
"description": "Original repo at http://svn.grimore.org/was.js",
"version": "1.0.0",
"main": "Gruntfile.js",
"main": "dist/was.min.js",
"directories": {
"test": "test"
},