was.js – Diff between revs 15 and 17

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 15 Rev 17
Line 3... Line 3...
3 /*************************************************************************/ 3 /*************************************************************************/
4 /* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */ 4 /* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */
5 /*************************************************************************/ 5 /*************************************************************************/
6 if (!Array.prototype.switch) { 6 if (!Array.prototype.switch) {
7 Array.prototype.switch = function(d, ...c) { 7 Array.prototype.switch = function(d, ...c) {
8 if(c.length % 2 != 0) 8 if(c.length % 2 !== 0) {
9 throw "Pairs of predicates expected for cases"; 9 throw "Pairs of predicates expected for cases";
-   10 }
Line 10... Line 11...
10 11
11 (Array.isArray(this) ? this : [ this ]).forEach((s) => { 12 (Array.isArray(this) ? this : [ this ]).forEach((s) => {
12 var m = false; 13 var m = false;
13 for(i = 0; i < c.length; i += 2) { 14 for(var i = 0; i < c.length; i += 2) {
14 if(!c[i](s)) 15 if(!c[i](s)) {
-   16 continue;
15 continue; 17 }
16 if(!c[i + 1](s)) 18 if(!c[i + 1](s)) {
-   19 continue;
17 continue; 20 }
18 m = true; 21 m = true;
Line 19... Line 22...
19 } 22 }
20 23
-   24 if(!m) {
21 if(!m) 25 d(s);
22 d(s) 26 }
23 }); 27 });
Line 24... Line 28...
24 }; 28 };
Line 29... Line 33...
29 /*************************************************************************/ 33 /*************************************************************************/
30 /* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */ 34 /* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */
31 /*************************************************************************/ 35 /*************************************************************************/
32 $.extend({ 36 $.extend({
33 switch: function(q, d, ...c) { 37 switch: function(q, d, ...c) {
34 if(c.length % 2 != 0) 38 if(c.length % 2 !== 0) {
35 throw "Pairs of predicates expected for cases"; 39 throw "Pairs of predicates expected for cases";
-   40 }
Line 36... Line 41...
36 41
37 (Array.isArray(q) ? q : [ q ]).forEach((s) => { 42 (Array.isArray(q) ? q : [ q ]).forEach((s) => {
38 var m = false; 43 var m = false;
39 for(i = 0; i < c.length; i += 2) { 44 for(var i = 0; i < c.length; i += 2) {
40 if(!c[i](s)) 45 if(!c[i](s)) {
-   46 continue;
41 continue; 47 }
42 if(!c[i + 1](s)) 48 if(!c[i + 1](s)) {
-   49 continue;
43 continue; 50 }
44 m = true; 51 m = true;
Line 45... Line 52...
45 } 52 }
46 53
-   54 if(!m) {
47 if(!m) 55 d(s);
48 d(s) 56 }
49 }); 57 });