was.js – Blame information for rev 14
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
14 | office | 1 | /*************************************************************************/ |
2 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
||
3 | /*************************************************************************/ |
||
4 | /* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */ |
||
5 | /*************************************************************************/ |
||
6 | if (!Array.prototype.switch) { |
||
7 | Array.prototype.switch = function(d, c) { |
||
8 | if(c.length % 2 != 0) |
||
9 | throw "Pairs of predicates expected for cases"; |
||
10 | |||
11 | this.forEach((s) => { |
||
12 | var m = false; |
||
13 | for(i = 0; i < c.length; i += 2) { |
||
14 | if(!c[i](s)) |
||
15 | continue; |
||
16 | if(!c[i + 1](s)) |
||
17 | continue; |
||
18 | m = true; |
||
19 | } |
||
20 | |||
21 | if(!m) |
||
22 | d(s) |
||
23 | }); |
||
24 | }; |
||
25 | } |
||
26 | |||
27 | /*************************************************************************/ |
||
28 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
||
29 | /*************************************************************************/ |
||
30 | /* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */ |
||
31 | /*************************************************************************/ |
||
32 | $.extend({ |
||
33 | switch: function(q, d, c) { |
||
34 | if(c.length % 2 != 0) |
||
35 | throw "Pairs of predicates expected for cases"; |
||
36 | |||
37 | q.forEach((s) => { |
||
38 | var m = false; |
||
39 | for(i = 0; i < c.length; i += 2) { |
||
40 | if(!c[i](s)) |
||
41 | continue; |
||
42 | if(!c[i + 1](s)) |
||
43 | continue; |
||
44 | m = true; |
||
45 | } |
||
46 | |||
47 | if(!m) |
||
48 | d(s) |
||
49 | }); |
||
50 | } |
||
51 | }); |