was.js – Diff between revs 34 and 35
?pathlinks?
Rev 34 | Rev 35 | |||
---|---|---|---|---|
Line 1... | Line 1... | |||
1 | /*! was.js - v1.0.1 - 2019-03-04 |
1 | /*! was.js - v1.0.1 - 2019-08-01 |
|
2 | * http://grimore.org |
2 | * http://grimore.org |
|
3 | * Copyright (c) 2019 [object Object]; Licensed GPL-3.0 */ |
3 | * Copyright (c) 2019 [object Object]; Licensed GPL-3.0 */ |
|
4 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
4 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
|
5 | /*************************************************************************/ |
5 | /*************************************************************************/ |
|
6 | function wasProduct(a, b) { |
6 | function wasProduct(a, b) { |
|
Line 217... | Line 217... | |||
217 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
217 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
|
218 | /*************************************************************************/ |
218 | /*************************************************************************/ |
|
219 | /* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */ |
219 | /* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */ |
|
220 | /*************************************************************************/ |
220 | /*************************************************************************/ |
|
221 | // Vanilla ES6 JavaScript |
221 | // Vanilla ES6 JavaScript |
|
222 | function wasSwitch(q, d, ...c) { |
222 | function wasSwitch() { |
|
223 | if(c.length % 2 !== 0) { |
223 | if(arguments.length - 2 % 2 !== 0) { |
|
224 | throw "Pairs of predicates expected for cases"; |
224 | throw "Pairs of predicates expected for cases"; |
|
225 | } |
225 | } |
|
Line 226... | Line 226... | |||
226 | |
226 | |
|
227 | (Array.isArray(q) ? q : [ q ]).forEach((s) => { |
227 | (Array.isArray(arguments[0]) ? arguments[0] : [ arguments[0] ]).forEach((s) => { |
|
228 | var m = false; |
228 | var m = false; |
|
229 | for(var i = 0; i < c.length; i += 2) { |
229 | for(var i = 2; i < arguments.length; i += 2) { |
|
230 | if(!c[i](s)) { |
230 | if(!arguments[i](s)) { |
|
231 | continue; |
231 | continue; |
|
232 | } |
232 | } |
|
233 | if(!c[i + 1](s)) { |
233 | if(!arguments[i + 1](s)) { |
|
234 | continue; |
234 | continue; |
|
235 | } |
235 | } |
|
236 | m = true; |
236 | m = true; |
|
Line 237... | Line 237... | |||
237 | } |
237 | } |
|
238 | |
238 | |
|
239 | if(!m) { |
239 | if(!m) { |
|
240 | d(s); |
240 | arguments[1](s); |
|
241 | } |
241 | } |
|
242 | }); |
242 | }); |
|
243 | } |
243 | } |
|
244 | if (!Array.prototype.switch) { |
244 | if (!Array.prototype.switch) { |
|
245 | Array.prototype.switch = function(d, ...c) { |
245 | Array.prototype.switch = function() { |
|
246 | wasSwitch(this, d, ...c); |
246 | wasSwitch(this, arguments[0], arguments.slice(1)); |
|
247 | }; |
247 | }; |
|
248 | } |
248 | } |
|
249 | // jQuery |
249 | // jQuery |