was.js – Blame information for rev 55
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
55 | office | 1 | /*************************************************************************/ |
2 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
||
3 | /*************************************************************************/ |
||
4 | /* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */ |
||
5 | /*************************************************************************/ |
||
6 | function wasSwitch(q, d, ...c) { |
||
7 | if(c.length % 2 !== 0) { |
||
8 | throw "Pairs of predicates expected for cases"; |
||
9 | } |
||
10 | |||
11 | (Array.isArray(q) ? q : [ q ]).forEach((s) => { |
||
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 | }); |
||
27 | } |
||
28 | if (!Array.prototype.switch) { |
||
29 | Array.prototype.switch = function() { |
||
30 | wasSwitch(this, arguments[0], arguments.slice(1)); |
||
31 | }; |
||
32 | } |
||
33 | // jQuery |
||
34 | if(typeof jQuery === 'function') { |
||
35 | $.extend({ |
||
36 | switch: wasSwitch |
||
37 | }); |
||
38 | } |
||
39 | |||
40 | /*************************************************************************/ |
||
41 | /* Node.JS package export. */ |
||
42 | /*************************************************************************/ |
||
43 | if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') { |
||
44 | module.exports.lambda = { |
||
45 | switch: wasSwitch |
||
46 | }; |
||
47 | } |