was.js – Blame information for rev 23
?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 | /*************************************************************************/ |
||
22 | office | 6 | function wasSwitch(q, d, ...c) { |
19 | office | 7 | if(c.length % 2 !== 0) { |
8 | throw "Pairs of predicates expected for cases"; |
||
9 | } |
||
10 | |||
22 | office | 11 | (Array.isArray(this) ? this : [ this ]).forEach((s) => { |
19 | office | 12 | var m = false; |
13 | for(var i = 0; i < c.length; i += 2) { |
||
14 | if(!c[i](s)) { |
||
15 | continue; |
||
16 | } |
||
17 | if(!c[i + 1](s)) { |
||
18 | continue; |
||
19 | } |
||
20 | m = true; |
||
21 | } |
||
22 | |||
23 | if(!m) { |
||
24 | d(s); |
||
25 | } |
||
26 | }); |
||
22 | office | 27 | } |
28 | |||
29 | // Vanilla ES6 JavaScript |
||
30 | if (!Array.prototype.switch) { |
||
31 | Array.prototype.switch = wasSwitch; |
||
32 | } |
||
33 | // jQuery |
||
23 | office | 34 | if(typeof jQuery === 'function') { |
35 | $.extend({ |
||
36 | switch: wasSwitch |
||
37 | }); |
||
38 | } |
||
22 | office | 39 | // Node.JS |
40 | module.exports = { |
||
41 | switch: wasSwitch |
||
20 | office | 42 | }; |