was.js – Diff between revs 14 and 15
?pathlinks?
Rev 14 | Rev 15 | |||
---|---|---|---|---|
Line 2... | Line 2... | |||
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 | 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"; |
|
Line 10... | Line 10... | |||
10 | |
10 | |
|
11 | this.forEach((s) => { |
11 | (Array.isArray(this) ? this : [ this ]).forEach((s) => { |
|
12 | var m = false; |
12 | var m = false; |
|
13 | for(i = 0; i < c.length; i += 2) { |
13 | for(i = 0; i < c.length; i += 2) { |
|
14 | if(!c[i](s)) |
14 | if(!c[i](s)) |
|
15 | continue; |
15 | continue; |
|
Line 28... | Line 28... | |||
28 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
28 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
|
29 | /*************************************************************************/ |
29 | /*************************************************************************/ |
|
30 | /* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */ |
30 | /* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */ |
|
31 | /*************************************************************************/ |
31 | /*************************************************************************/ |
|
32 | $.extend({ |
32 | $.extend({ |
|
33 | switch: function(q, d, c) { |
33 | switch: function(q, d, ...c) { |
|
34 | if(c.length % 2 != 0) |
34 | if(c.length % 2 != 0) |
|
35 | throw "Pairs of predicates expected for cases"; |
35 | throw "Pairs of predicates expected for cases"; |
|
Line 36... | Line 36... | |||
36 | |
36 | |
|
37 | q.forEach((s) => { |
37 | (Array.isArray(q) ? q : [ q ]).forEach((s) => { |
|
38 | var m = false; |
38 | var m = false; |
|
39 | for(i = 0; i < c.length; i += 2) { |
39 | for(i = 0; i < c.length; i += 2) { |
|
40 | if(!c[i](s)) |
40 | if(!c[i](s)) |
|
41 | continue; |
41 | continue; |