was.js – Blame information for rev 15
?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) { |
14 | office | 8 | if(c.length % 2 != 0) |
9 | throw "Pairs of predicates expected for cases"; |
||
10 | |||
15 | office | 11 | (Array.isArray(this) ? this : [ this ]).forEach((s) => { |
14 | office | 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({ |
||
15 | office | 33 | switch: function(q, d, ...c) { |
14 | office | 34 | if(c.length % 2 != 0) |
35 | throw "Pairs of predicates expected for cases"; |
||
36 | |||
15 | office | 37 | (Array.isArray(q) ? q : [ q ]).forEach((s) => { |
14 | office | 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 | }); |