was.js
/trunk/dist/was.js |
@@ -1,4 +1,4 @@ |
/*! was - v1.0.0 - 2017-05-29 |
/*! was.js - v1.0.0 - 2017-12-13 |
* http://grimore.org |
* Copyright (c) 2017 Wizardry and Steamworks <office@grimore.org>; Licensed GPL-3.0 */ |
/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
@@ -202,6 +202,48 @@ |
return o; |
} |
|
/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
/*************************************************************************/ |
/* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */ |
/*************************************************************************/ |
function wasSwitch(q, 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); |
} |
}); |
} |
|
// Vanilla ES6 JavaScript |
if (!Array.prototype.switch) { |
Array.prototype.switch = wasSwitch; |
} |
// jQuery |
if(typeof jQuery === 'function') { |
$.extend({ |
switch: wasSwitch |
}); |
} |
// Node.JS |
module.exports = { |
switch: wasSwitch |
}; |
|
/* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */ |
/*************************************************************************/ |
function wasMapValueToRange(value, xMin, xMax, yMin, yMax) { |