was.js – Diff between revs 22 and 23

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 22 Rev 23
1 /*************************************************************************/ 1 /*************************************************************************/
2 /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ 2 /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */
3 /*************************************************************************/ 3 /*************************************************************************/
4 /* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */ 4 /* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */
5 /*************************************************************************/ 5 /*************************************************************************/
6 function wasSwitch(q, d, ...c) { 6 function wasSwitch(q, d, ...c) {
7 if(c.length % 2 !== 0) { 7 if(c.length % 2 !== 0) {
8 throw "Pairs of predicates expected for cases"; 8 throw "Pairs of predicates expected for cases";
9 } 9 }
10 10
11 (Array.isArray(this) ? this : [ this ]).forEach((s) => { 11 (Array.isArray(this) ? this : [ this ]).forEach((s) => {
12 var m = false; 12 var m = false;
13 for(var i = 0; i < c.length; i += 2) { 13 for(var i = 0; i < c.length; i += 2) {
14 if(!c[i](s)) { 14 if(!c[i](s)) {
15 continue; 15 continue;
16 } 16 }
17 if(!c[i + 1](s)) { 17 if(!c[i + 1](s)) {
18 continue; 18 continue;
19 } 19 }
20 m = true; 20 m = true;
21 } 21 }
22 22
23 if(!m) { 23 if(!m) {
24 d(s); 24 d(s);
25 } 25 }
26 }); 26 });
27 } 27 }
28   28  
29 // Vanilla ES6 JavaScript 29 // Vanilla ES6 JavaScript
30 if (!Array.prototype.switch) { 30 if (!Array.prototype.switch) {
31 Array.prototype.switch = wasSwitch; 31 Array.prototype.switch = wasSwitch;
32 } 32 }
33 // jQuery 33 // jQuery
-   34 if(typeof jQuery === 'function') {
34 $.extend({ 35 $.extend({
35 switch: wasSwitch 36 switch: wasSwitch
-   37 });
36 }); 38 }
37 // Node.JS 39 // Node.JS
38 module.exports = { 40 module.exports = {
39 switch: wasSwitch 41 switch: wasSwitch
40 }; 42 };
41   43