was.js – Blame information for rev 34
?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 | |||
29 | office | 12 | (Array.isArray(q) ? q : [ q ]).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) { |
||
29 | office | 30 | Array.prototype.switch = function(d, ...c) { |
30 | office | 31 | wasSwitch(this, d, ...c); |
29 | office | 32 | }; |
22 | office | 33 | } |
34 | // jQuery |
||
23 | office | 35 | if(typeof jQuery === 'function') { |
36 | $.extend({ |
||
37 | switch: wasSwitch |
||
38 | }); |
||
39 | } |
||
25 | office | 40 | |
41 | /*************************************************************************/ |
||
42 | /* Node.JS package export. */ |
||
43 | /*************************************************************************/ |
||
34 | office | 44 | if(typeof variable !== 'undefined') { |
45 | module.exports.lambda = { |
||
46 | switch: wasSwitch |
||
47 | }; |
||
48 | } |