was.js – Diff between revs 34 and 35

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 34 Rev 35
Line 1... Line 1...
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 // Vanilla ES6 JavaScript -  
7 function wasSwitch(q, d, ...c) { 6 function wasSwitch() {
8 if(c.length % 2 !== 0) { 7 if(arguments.length % 2 !== 0) {
9 throw "Pairs of predicates expected for cases"; 8 throw "Pairs of predicates expected for cases";
10 } 9 }
Line 11... Line 10...
11 10
12 (Array.isArray(q) ? q : [ q ]).forEach((s) => { 11 (Array.isArray(arguments[0]) ? arguments[0] : [ arguments[0] ]).forEach((s) => {
13 var m = false; 12 var m = false;
14 for(var i = 0; i < c.length; i += 2) { 13 for(var i = 2; i < arguments.length; i += 2) {
15 if(!c[i](s)) { 14 if(!arguments[i](s)) {
16 continue; 15 continue;
17 } 16 }
18 if(!c[i + 1](s)) { 17 if(!arguments[i + 1](s)) {
19 continue; 18 continue;
20 } 19 }
21 m = true; 20 m = true;
Line 22... Line 21...
22 } 21 }
23 22
24 if(!m) { 23 if(!m) {
25 d(s); 24 arguments[1](s);
26 } 25 }
27 }); 26 });
28 } 27 }
29 if (!Array.prototype.switch) { 28 if (!Array.prototype.switch) {
30 Array.prototype.switch = function(d, ...c) { 29 Array.prototype.switch = function() {
31 wasSwitch(this, d, ...c); 30 wasSwitch(this, arguments[0], arguments.slice(1));
32 }; 31 };
33 } 32 }
34 // jQuery 33 // jQuery