was.js – Blame information for rev 47

Subversion Repositories:
Rev:
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 /*************************************************************************/
47 office 6 function wasSwitch(q, d, ...c) {
7 if(c.length % 2 !== 0) {
19 office 8 throw "Pairs of predicates expected for cases";
9 }
47 office 10  
11 (Array.isArray(q) ? q : [ q ]).forEach((s) => {
19 office 12 var m = false;
47 office 13 for(var i = 0; i < c.length; i += 2) {
14 if(!c[i](s)) {
19 office 15 continue;
16 }
47 office 17 if(!c[i + 1](s)) {
19 office 18 continue;
19 }
20 m = true;
21 }
47 office 22  
19 office 23 if(!m) {
47 office 24 d(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 /*************************************************************************/
41 office 43 if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
34 office 44 module.exports.lambda = {
45 switch: wasSwitch
46 };
47 }