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