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