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