was.js – Diff between revs 23 and 25
?pathlinks?
Rev 23 | Rev 25 | |||
---|---|---|---|---|
Line 1... | Line 1... | |||
1 | /*************************************************************************/ |
1 | /*************************************************************************/ |
|
2 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
2 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
|
3 | /*************************************************************************/ |
3 | /*************************************************************************/ |
|
4 | /* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */ |
4 | /* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */ |
|
5 | /*************************************************************************/ |
5 | /*************************************************************************/ |
|
- | 6 | // Vanilla ES6 JavaScript |
||
6 | function wasSwitch(q, d, ...c) { |
7 | function wasSwitch(q, d, ...c) { |
|
7 | if(c.length % 2 !== 0) { |
8 | if(c.length % 2 !== 0) { |
|
8 | throw "Pairs of predicates expected for cases"; |
9 | throw "Pairs of predicates expected for cases"; |
|
9 | } |
10 | } |
|
Line 23... | Line 24... | |||
23 | if(!m) { |
24 | if(!m) { |
|
24 | d(s); |
25 | d(s); |
|
25 | } |
26 | } |
|
26 | }); |
27 | }); |
|
27 | } |
28 | } |
|
28 | |
- | ||
29 | // Vanilla ES6 JavaScript |
- | ||
30 | if (!Array.prototype.switch) { |
29 | if (!Array.prototype.switch) { |
|
31 | Array.prototype.switch = wasSwitch; |
30 | Array.prototype.switch = wasSwitch; |
|
32 | } |
31 | } |
|
33 | // jQuery |
32 | // jQuery |
|
34 | if(typeof jQuery === 'function') { |
33 | if(typeof jQuery === 'function') { |
|
35 | $.extend({ |
34 | $.extend({ |
|
36 | switch: wasSwitch |
35 | switch: wasSwitch |
|
37 | }); |
36 | }); |
|
38 | } |
37 | } |
|
39 | // Node.JS |
38 | |
|
- | 39 | /*************************************************************************/ |
||
- | 40 | /* Node.JS package export. */ |
||
- | 41 | /*************************************************************************/ |
||
40 | module.exports = { |
42 | module.exports.lambda.aggregators = { |
|
41 | switch: wasSwitch |
43 | switch: wasSwitch |
|
42 | }; |
44 | }; |