was.js – Diff between revs 41 and 47
?pathlinks?
Rev 41 | Rev 47 | |||
---|---|---|---|---|
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 | function wasSwitch() { |
6 | function wasSwitch(q, d, ...c) { |
|
7 | if(arguments.length % 2 !== 0) { |
7 | if(c.length % 2 !== 0) { |
|
8 | throw "Pairs of predicates expected for cases"; |
8 | throw "Pairs of predicates expected for cases"; |
|
9 | } |
9 | } |
|
Line 10... | Line 10... | |||
10 | |
10 | |
|
11 | (Array.isArray(arguments[0]) ? arguments[0] : [ arguments[0] ]).forEach(function(s) { |
11 | (Array.isArray(q) ? q : [ q ]).forEach((s) => { |
|
12 | var m = false; |
12 | var m = false; |
|
13 | for(var i = 2; i < arguments.length; i += 2) { |
13 | for(var i = 0; i < c.length; i += 2) { |
|
14 | if(!arguments[i](s)) { |
14 | if(!c[i](s)) { |
|
15 | continue; |
15 | continue; |
|
16 | } |
16 | } |
|
17 | if(!arguments[i + 1](s)) { |
17 | if(!c[i + 1](s)) { |
|
18 | continue; |
18 | continue; |
|
19 | } |
19 | } |
|
20 | m = true; |
20 | m = true; |
|
Line 21... | Line 21... | |||
21 | } |
21 | } |
|
22 | |
22 | |
|
23 | if(!m) { |
23 | if(!m) { |
|
24 | arguments[1](s); |
24 | d(s); |
|
25 | } |
25 | } |
|
26 | }); |
26 | }); |
|
27 | } |
27 | } |