1 | function F() {
|
2 | return false;
|
3 | }
|
4 |
|
5 | function T() {
|
6 | return true;
|
7 | }
|
8 |
|
9 | function add(a, b) {
|
10 | if (arguments.length === 1) return _b => add(a, _b);
|
11 | return Number(a) + Number(b);
|
12 | }
|
13 |
|
14 | function curry(fn, args = []) {
|
15 | return (..._args) => (rest => rest.length >= fn.length ? fn(...rest) : curry(fn, rest))([...args, ..._args]);
|
16 | }
|
17 |
|
18 | function adjustFn(index, replaceFn, list) {
|
19 | const actualIndex = index < 0 ? list.length + index : index;
|
20 | if (index >= list.length || actualIndex < 0) return list;
|
21 | const clone = list.slice();
|
22 | clone[actualIndex] = replaceFn(clone[actualIndex]);
|
23 | return clone;
|
24 | }
|
25 |
|
26 | const adjust = curry(adjustFn);
|
27 |
|
28 | function all(predicate, list) {
|
29 | if (arguments.length === 1) return _list => all(predicate, _list);
|
30 |
|
31 | for (let i = 0; i < list.length; i++) {
|
32 | if (!predicate(list[i])) return false;
|
33 | }
|
34 |
|
35 | return true;
|
36 | }
|
37 |
|
38 | function allPass(predicates) {
|
39 | return input => {
|
40 | let counter = 0;
|
41 |
|
42 | while (counter < predicates.length) {
|
43 | if (!predicates[counter](input)) {
|
44 | return false;
|
45 | }
|
46 |
|
47 | counter++;
|
48 | }
|
49 |
|
50 | return true;
|
51 | };
|
52 | }
|
53 |
|
54 | function always(x) {
|
55 | return () => x;
|
56 | }
|
57 |
|
58 | function and(a, b) {
|
59 | if (arguments.length === 1) return _b => and(a, _b);
|
60 | return a && b;
|
61 | }
|
62 |
|
63 | function any(predicate, list) {
|
64 | if (arguments.length === 1) return _list => any(predicate, _list);
|
65 | let counter = 0;
|
66 |
|
67 | while (counter < list.length) {
|
68 | if (predicate(list[counter], counter)) {
|
69 | return true;
|
70 | }
|
71 |
|
72 | counter++;
|
73 | }
|
74 |
|
75 | return false;
|
76 | }
|
77 |
|
78 | function anyPass(predicates) {
|
79 | return input => {
|
80 | let counter = 0;
|
81 |
|
82 | while (counter < predicates.length) {
|
83 | if (predicates[counter](input)) {
|
84 | return true;
|
85 | }
|
86 |
|
87 | counter++;
|
88 | }
|
89 |
|
90 | return false;
|
91 | };
|
92 | }
|
93 |
|
94 | function append(x, input) {
|
95 | if (arguments.length === 1) return _input => append(x, _input);
|
96 | if (typeof input === 'string') return input.split('').concat(x);
|
97 | const clone = input.slice();
|
98 | clone.push(x);
|
99 | return clone;
|
100 | }
|
101 |
|
102 | const _isArray = Array.isArray;
|
103 |
|
104 | function __findHighestArity(spec, max = 0) {
|
105 | for (const key in spec) {
|
106 | if (spec.hasOwnProperty(key) === false || key === 'constructor') continue;
|
107 |
|
108 | if (typeof spec[key] === 'object') {
|
109 | max = Math.max(max, __findHighestArity(spec[key]));
|
110 | }
|
111 |
|
112 | if (typeof spec[key] === 'function') {
|
113 | max = Math.max(max, spec[key].length);
|
114 | }
|
115 | }
|
116 |
|
117 | return max;
|
118 | }
|
119 |
|
120 | function __filterUndefined() {
|
121 | const defined = [];
|
122 | let i = 0;
|
123 | const l = arguments.length;
|
124 |
|
125 | while (i < l) {
|
126 | if (typeof arguments[i] === 'undefined') break;
|
127 | defined[i] = arguments[i];
|
128 | i++;
|
129 | }
|
130 |
|
131 | return defined;
|
132 | }
|
133 |
|
134 | function __applySpecWithArity(spec, arity, cache) {
|
135 | const remaining = arity - cache.length;
|
136 | if (remaining === 1) return x => __applySpecWithArity(spec, arity, __filterUndefined(...cache, x));
|
137 | if (remaining === 2) return (x, y) => __applySpecWithArity(spec, arity, __filterUndefined(...cache, x, y));
|
138 | if (remaining === 3) return (x, y, z) => __applySpecWithArity(spec, arity, __filterUndefined(...cache, x, y, z));
|
139 | if (remaining === 4) return (x, y, z, a) => __applySpecWithArity(spec, arity, __filterUndefined(...cache, x, y, z, a));
|
140 | if (remaining > 4) return (...args) => __applySpecWithArity(spec, arity, __filterUndefined(...cache, ...args));
|
141 |
|
142 | if (_isArray(spec)) {
|
143 | const ret = [];
|
144 | let i = 0;
|
145 | const l = spec.length;
|
146 |
|
147 | for (; i < l; i++) {
|
148 | if (typeof spec[i] === 'object' || _isArray(spec[i])) {
|
149 | ret[i] = __applySpecWithArity(spec[i], arity, cache);
|
150 | }
|
151 |
|
152 | if (typeof spec[i] === 'function') {
|
153 | ret[i] = spec[i](...cache);
|
154 | }
|
155 | }
|
156 |
|
157 | return ret;
|
158 | }
|
159 |
|
160 | const ret = {};
|
161 |
|
162 | for (const key in spec) {
|
163 | if (spec.hasOwnProperty(key) === false || key === 'constructor') continue;
|
164 |
|
165 | if (typeof spec[key] === 'object') {
|
166 | ret[key] = __applySpecWithArity(spec[key], arity, cache);
|
167 | continue;
|
168 | }
|
169 |
|
170 | if (typeof spec[key] === 'function') {
|
171 | ret[key] = spec[key](...cache);
|
172 | }
|
173 | }
|
174 |
|
175 | return ret;
|
176 | }
|
177 |
|
178 | function applySpec(spec, ...args) {
|
179 | const arity = __findHighestArity(spec);
|
180 |
|
181 | if (arity === 0) {
|
182 | return () => ({});
|
183 | }
|
184 |
|
185 | const toReturn = __applySpecWithArity(spec, arity, args);
|
186 |
|
187 | return toReturn;
|
188 | }
|
189 |
|
190 | function assocFn(prop, newValue, obj) {
|
191 | return Object.assign({}, obj, {
|
192 | [prop]: newValue
|
193 | });
|
194 | }
|
195 |
|
196 | const assoc = curry(assocFn);
|
197 |
|
198 | function _isInteger(n) {
|
199 | return n << 0 === n;
|
200 | }
|
201 | var _isInteger$1 = Number.isInteger || _isInteger;
|
202 |
|
203 | function assocPathFn(path, newValue, input) {
|
204 | const pathArrValue = typeof path === 'string' ? path.split('.').map(x => _isInteger(Number(x)) ? Number(x) : x) : path;
|
205 |
|
206 | if (pathArrValue.length === 0) {
|
207 | return newValue;
|
208 | }
|
209 |
|
210 | const index = pathArrValue[0];
|
211 |
|
212 | if (pathArrValue.length > 1) {
|
213 | const condition = typeof input !== 'object' || input === null || !input.hasOwnProperty(index);
|
214 | const nextinput = condition ? _isInteger(pathArrValue[1]) ? [] : {} : input[index];
|
215 | newValue = assocPathFn(Array.prototype.slice.call(pathArrValue, 1), newValue, nextinput);
|
216 | }
|
217 |
|
218 | if (_isInteger(index) && _isArray(input)) {
|
219 | const arr = input.slice();
|
220 | arr[index] = newValue;
|
221 | return arr;
|
222 | }
|
223 |
|
224 | return assoc(index, newValue, input);
|
225 | }
|
226 |
|
227 | const assocPath = curry(assocPathFn);
|
228 |
|
229 | function both(f, g) {
|
230 | if (arguments.length === 1) return _g => both(f, _g);
|
231 | return (...input) => f(...input) && g(...input);
|
232 | }
|
233 |
|
234 | function chain(fn, list) {
|
235 | if (arguments.length === 1) {
|
236 | return _list => chain(fn, _list);
|
237 | }
|
238 |
|
239 | return [].concat(...list.map(fn));
|
240 | }
|
241 |
|
242 | function clampFn(min, max, input) {
|
243 | if (min > max) {
|
244 | throw new Error('min must not be greater than max in clamp(min, max, value)');
|
245 | }
|
246 |
|
247 | if (input >= min && input <= max) return input;
|
248 | if (input > max) return max;
|
249 | if (input < min) return min;
|
250 | }
|
251 |
|
252 | const clamp = curry(clampFn);
|
253 |
|
254 | function clone(input) {
|
255 | const out = _isArray(input) ? Array(input.length) : {};
|
256 | if (input && input.getTime) return new Date(input.getTime());
|
257 |
|
258 | for (const key in input) {
|
259 | const v = input[key];
|
260 | out[key] = typeof v === 'object' && v !== null ? v.getTime ? new Date(v.getTime()) : clone(v) : v;
|
261 | }
|
262 |
|
263 | return out;
|
264 | }
|
265 |
|
266 | function complement(fn) {
|
267 | return (...input) => !fn(...input);
|
268 | }
|
269 |
|
270 | function compose(...fns) {
|
271 | if (fns.length === 0) {
|
272 | throw new Error('compose requires at least one argument');
|
273 | }
|
274 |
|
275 | return (...args) => {
|
276 | const list = fns.slice();
|
277 |
|
278 | if (list.length > 0) {
|
279 | const fn = list.pop();
|
280 | let result = fn(...args);
|
281 |
|
282 | while (list.length > 0) {
|
283 | result = list.pop()(result);
|
284 | }
|
285 |
|
286 | return result;
|
287 | }
|
288 | };
|
289 | }
|
290 |
|
291 | function concat(x, y) {
|
292 | if (arguments.length === 1) return _y => concat(x, _y);
|
293 | return typeof x === 'string' ? `${x}${y}` : [...x, ...y];
|
294 | }
|
295 |
|
296 | function cond(conditions) {
|
297 | return input => {
|
298 | let done = false;
|
299 | let toReturn;
|
300 | conditions.forEach(([predicate, resultClosure]) => {
|
301 | if (!done && predicate(input)) {
|
302 | done = true;
|
303 | toReturn = resultClosure(input);
|
304 | }
|
305 | });
|
306 | return toReturn;
|
307 | };
|
308 | }
|
309 |
|
310 | function _curryN(n, cache, fn) {
|
311 | return function () {
|
312 | let ci = 0;
|
313 | let ai = 0;
|
314 | const cl = cache.length;
|
315 | const al = arguments.length;
|
316 | const args = new Array(cl + al);
|
317 |
|
318 | while (ci < cl) {
|
319 | args[ci] = cache[ci];
|
320 | ci++;
|
321 | }
|
322 |
|
323 | while (ai < al) {
|
324 | args[cl + ai] = arguments[ai];
|
325 | ai++;
|
326 | }
|
327 |
|
328 | const remaining = n - args.length;
|
329 | return args.length >= n ? fn.apply(this, args) : _arity(remaining, _curryN(n, args, fn));
|
330 | };
|
331 | }
|
332 |
|
333 | function _arity(n, fn) {
|
334 | switch (n) {
|
335 | case 0:
|
336 | return function () {
|
337 | return fn.apply(this, arguments);
|
338 | };
|
339 |
|
340 | case 1:
|
341 | return function (_1) {
|
342 | return fn.apply(this, arguments);
|
343 | };
|
344 |
|
345 | case 2:
|
346 | return function (_1, _2) {
|
347 | return fn.apply(this, arguments);
|
348 | };
|
349 |
|
350 | case 3:
|
351 | return function (_1, _2, _3) {
|
352 | return fn.apply(this, arguments);
|
353 | };
|
354 |
|
355 | case 4:
|
356 | return function (_1, _2, _3, _4) {
|
357 | return fn.apply(this, arguments);
|
358 | };
|
359 |
|
360 | case 5:
|
361 | return function (_1, _2, _3, _4, _5) {
|
362 | return fn.apply(this, arguments);
|
363 | };
|
364 |
|
365 | case 6:
|
366 | return function (_1, _2, _3, _4, _5, _6) {
|
367 | return fn.apply(this, arguments);
|
368 | };
|
369 |
|
370 | case 7:
|
371 | return function (_1, _2, _3, _4, _5, _6, _7) {
|
372 | return fn.apply(this, arguments);
|
373 | };
|
374 |
|
375 | case 8:
|
376 | return function (_1, _2, _3, _4, _5, _6, _7, _8) {
|
377 | return fn.apply(this, arguments);
|
378 | };
|
379 |
|
380 | case 9:
|
381 | return function (_1, _2, _3, _4, _5, _6, _7, _8, _9) {
|
382 | return fn.apply(this, arguments);
|
383 | };
|
384 |
|
385 | default:
|
386 | return function (_1, _2, _3, _4, _5, _6, _7, _8, _9, _10) {
|
387 | return fn.apply(this, arguments);
|
388 | };
|
389 | }
|
390 | }
|
391 |
|
392 | function curryN(n, fn) {
|
393 | if (arguments.length === 1) return _fn => curryN(n, _fn);
|
394 |
|
395 | if (n > 10) {
|
396 | throw new Error('First argument to _arity must be a non-negative integer no greater than ten');
|
397 | }
|
398 |
|
399 | return _arity(n, _curryN(n, [], fn));
|
400 | }
|
401 |
|
402 | const _keys = Object.keys;
|
403 |
|
404 | function mapArray(fn, list, isIndexed = false) {
|
405 | let index = 0;
|
406 | const willReturn = Array(list.length);
|
407 |
|
408 | while (index < list.length) {
|
409 | willReturn[index] = isIndexed ? fn(list[index], index) : fn(list[index]);
|
410 | index++;
|
411 | }
|
412 |
|
413 | return willReturn;
|
414 | }
|
415 | function mapObject(fn, obj) {
|
416 | let index = 0;
|
417 |
|
418 | const keys = _keys(obj);
|
419 |
|
420 | const len = keys.length;
|
421 | const willReturn = {};
|
422 |
|
423 | while (index < len) {
|
424 | const key = keys[index];
|
425 | willReturn[key] = fn(obj[key], key, obj);
|
426 | index++;
|
427 | }
|
428 |
|
429 | return willReturn;
|
430 | }
|
431 | function map(fn, list) {
|
432 | if (arguments.length === 1) return _list => map(fn, _list);
|
433 | if (list === undefined) return [];
|
434 | if (_isArray(list)) return mapArray(fn, list);
|
435 | return mapObject(fn, list);
|
436 | }
|
437 |
|
438 | function max(x, y) {
|
439 | if (arguments.length === 1) return _y => max(x, _y);
|
440 | return y > x ? y : x;
|
441 | }
|
442 |
|
443 | function reduceFn(reducer, acc, list) {
|
444 | if (!_isArray(list)) {
|
445 | throw new TypeError('reduce: list must be array or iterable');
|
446 | }
|
447 |
|
448 | let index = 0;
|
449 | const len = list.length;
|
450 |
|
451 | while (index < len) {
|
452 | acc = reducer(acc, list[index], index, list);
|
453 | index++;
|
454 | }
|
455 |
|
456 | return acc;
|
457 | }
|
458 |
|
459 | const reduce = curry(reduceFn);
|
460 |
|
461 | function converge(fn, transformers) {
|
462 | if (arguments.length === 1) return _transformers => converge(fn, _transformers);
|
463 | const highestArity = reduce((a, b) => max(a, b.length), 0, transformers);
|
464 | return curryN(highestArity, function () {
|
465 | return fn.apply(this, map(g => g.apply(this, arguments), transformers));
|
466 | });
|
467 | }
|
468 |
|
469 | const dec = x => x - 1;
|
470 |
|
471 | function isFalsy(input) {
|
472 | return input === undefined || input === null || Number.isNaN(input) === true;
|
473 | }
|
474 |
|
475 | function defaultTo(defaultArgument, input) {
|
476 | if (arguments.length === 1) {
|
477 | return _input => defaultTo(defaultArgument, _input);
|
478 | }
|
479 |
|
480 | return isFalsy(input) ? defaultArgument : input;
|
481 | }
|
482 |
|
483 | function type(input) {
|
484 | const typeOf = typeof input;
|
485 |
|
486 | if (input === null) {
|
487 | return 'Null';
|
488 | } else if (input === undefined) {
|
489 | return 'Undefined';
|
490 | } else if (typeOf === 'boolean') {
|
491 | return 'Boolean';
|
492 | } else if (typeOf === 'number') {
|
493 | return Number.isNaN(input) ? 'NaN' : 'Number';
|
494 | } else if (typeOf === 'string') {
|
495 | return 'String';
|
496 | } else if (_isArray(input)) {
|
497 | return 'Array';
|
498 | } else if (typeOf === 'symbol') {
|
499 | return 'Symbol';
|
500 | } else if (input instanceof RegExp) {
|
501 | return 'RegExp';
|
502 | }
|
503 |
|
504 | const asStr = input && input.toString ? input.toString() : '';
|
505 | if (['true', 'false'].includes(asStr)) return 'Boolean';
|
506 | if (!Number.isNaN(Number(asStr))) return 'Number';
|
507 | if (asStr.startsWith('async')) return 'Async';
|
508 | if (asStr === '[object Promise]') return 'Promise';
|
509 | if (typeOf === 'function') return 'Function';
|
510 | if (input instanceof String) return 'String';
|
511 | return 'Object';
|
512 | }
|
513 |
|
514 | function parseError(maybeError) {
|
515 | const typeofError = maybeError.__proto__.toString();
|
516 |
|
517 | if (!['Error', 'TypeError'].includes(typeofError)) return [];
|
518 | return [typeofError, maybeError.message];
|
519 | }
|
520 |
|
521 | function parseDate(maybeDate) {
|
522 | if (!maybeDate.toDateString) return [false];
|
523 | return [true, maybeDate.getTime()];
|
524 | }
|
525 |
|
526 | function parseRegex(maybeRegex) {
|
527 | if (maybeRegex.constructor !== RegExp) return [false];
|
528 | return [true, maybeRegex.toString()];
|
529 | }
|
530 |
|
531 | function equals(a, b) {
|
532 | if (arguments.length === 1) return _b => equals(a, _b);
|
533 | const aType = type(a);
|
534 | if (aType !== type(b)) return false;
|
535 |
|
536 | if (aType === 'Function') {
|
537 | return a.name === undefined ? false : a.name === b.name;
|
538 | }
|
539 |
|
540 | if (['NaN', 'Undefined', 'Null'].includes(aType)) return true;
|
541 |
|
542 | if (aType === 'Number') {
|
543 | if (Object.is(-0, a) !== Object.is(-0, b)) return false;
|
544 | return a.toString() === b.toString();
|
545 | }
|
546 |
|
547 | if (['String', 'Boolean'].includes(aType)) {
|
548 | return a.toString() === b.toString();
|
549 | }
|
550 |
|
551 | if (aType === 'Array') {
|
552 | const aClone = Array.from(a);
|
553 | const bClone = Array.from(b);
|
554 |
|
555 | if (aClone.toString() !== bClone.toString()) {
|
556 | return false;
|
557 | }
|
558 |
|
559 | let loopArrayFlag = true;
|
560 | aClone.forEach((aCloneInstance, aCloneIndex) => {
|
561 | if (loopArrayFlag) {
|
562 | if (aCloneInstance !== bClone[aCloneIndex] && !equals(aCloneInstance, bClone[aCloneIndex])) {
|
563 | loopArrayFlag = false;
|
564 | }
|
565 | }
|
566 | });
|
567 | return loopArrayFlag;
|
568 | }
|
569 |
|
570 | const aRegex = parseRegex(a);
|
571 | const bRegex = parseRegex(b);
|
572 |
|
573 | if (aRegex[0]) {
|
574 | return bRegex[0] ? aRegex[1] === bRegex[1] : false;
|
575 | } else if (bRegex[0]) return false;
|
576 |
|
577 | const aDate = parseDate(a);
|
578 | const bDate = parseDate(b);
|
579 |
|
580 | if (aDate[0]) {
|
581 | return bDate[0] ? aDate[1] === bDate[1] : false;
|
582 | } else if (bDate[0]) return false;
|
583 |
|
584 | const aError = parseError(a);
|
585 | const bError = parseError(b);
|
586 |
|
587 | if (aError[0]) {
|
588 | return bError[0] ? aError[0] === bError[0] && aError[1] === bError[1] : false;
|
589 | }
|
590 |
|
591 | if (aType === 'Object') {
|
592 | const aKeys = Object.keys(a);
|
593 |
|
594 | if (aKeys.length !== Object.keys(b).length) {
|
595 | return false;
|
596 | }
|
597 |
|
598 | let loopObjectFlag = true;
|
599 | aKeys.forEach(aKeyInstance => {
|
600 | if (loopObjectFlag) {
|
601 | const aValue = a[aKeyInstance];
|
602 | const bValue = b[aKeyInstance];
|
603 |
|
604 | if (aValue !== bValue && !equals(aValue, bValue)) {
|
605 | loopObjectFlag = false;
|
606 | }
|
607 | }
|
608 | });
|
609 | return loopObjectFlag;
|
610 | }
|
611 |
|
612 | return false;
|
613 | }
|
614 |
|
615 | function includesArray(valueToFind, input) {
|
616 | let index = -1;
|
617 |
|
618 | while (++index < input.length) {
|
619 | if (equals(input[index], valueToFind)) {
|
620 | return true;
|
621 | }
|
622 | }
|
623 |
|
624 | return false;
|
625 | }
|
626 | function includes(valueToFind, input) {
|
627 | if (arguments.length === 1) return _input => includes(valueToFind, _input);
|
628 |
|
629 | if (typeof input === 'string') {
|
630 | return input.includes(valueToFind);
|
631 | }
|
632 |
|
633 | if (!input) {
|
634 | throw new TypeError(`Cannot read property \'indexOf\' of ${input}`);
|
635 | }
|
636 |
|
637 | if (!_isArray(input)) return false;
|
638 | return includesArray(valueToFind, input);
|
639 | }
|
640 |
|
641 | function uniq(list) {
|
642 | let index = -1;
|
643 | const willReturn = [];
|
644 |
|
645 | while (++index < list.length) {
|
646 | const value = list[index];
|
647 |
|
648 | if (!includes(value, willReturn)) {
|
649 | willReturn.push(value);
|
650 | }
|
651 | }
|
652 |
|
653 | return willReturn;
|
654 | }
|
655 |
|
656 | function difference(a, b) {
|
657 | if (arguments.length === 1) return _b => difference(a, _b);
|
658 | return uniq(a).filter(aInstance => !includes(aInstance, b));
|
659 | }
|
660 |
|
661 | function dissoc(prop, obj) {
|
662 | if (arguments.length === 1) return _obj => dissoc(prop, _obj);
|
663 | if (obj === null || obj === undefined) return {};
|
664 | const willReturn = {};
|
665 |
|
666 | for (const p in obj) {
|
667 | willReturn[p] = obj[p];
|
668 | }
|
669 |
|
670 | delete willReturn[prop];
|
671 | return willReturn;
|
672 | }
|
673 |
|
674 | function divide(a, b) {
|
675 | if (arguments.length === 1) return _b => divide(a, _b);
|
676 | return a / b;
|
677 | }
|
678 |
|
679 | function drop(howManyToDrop, listOrString) {
|
680 | if (arguments.length === 1) return _list => drop(howManyToDrop, _list);
|
681 | return listOrString.slice(howManyToDrop > 0 ? howManyToDrop : 0);
|
682 | }
|
683 |
|
684 | function dropLast(howManyToDrop, listOrString) {
|
685 | if (arguments.length === 1) {
|
686 | return _listOrString => dropLast(howManyToDrop, _listOrString);
|
687 | }
|
688 |
|
689 | return howManyToDrop > 0 ? listOrString.slice(0, -howManyToDrop) : listOrString.slice();
|
690 | }
|
691 |
|
692 | function dropLastWhile(predicate, iterable) {
|
693 | if (arguments.length === 1) {
|
694 | return _iterable => dropLastWhile(predicate, _iterable);
|
695 | }
|
696 |
|
697 | if (iterable.length === 0) return iterable;
|
698 |
|
699 | const isArray = _isArray(iterable);
|
700 |
|
701 | if (typeof predicate !== 'function') {
|
702 | throw new Error(`'predicate' is from wrong type ${typeof predicate}`);
|
703 | }
|
704 |
|
705 | if (!isArray && typeof iterable !== 'string') {
|
706 | throw new Error(`'iterable' is from wrong type ${typeof iterable}`);
|
707 | }
|
708 |
|
709 | let found = false;
|
710 | const toReturn = [];
|
711 | let counter = iterable.length;
|
712 |
|
713 | while (counter > 0) {
|
714 | counter--;
|
715 |
|
716 | if (!found && predicate(iterable[counter]) === false) {
|
717 | found = true;
|
718 | toReturn.push(iterable[counter]);
|
719 | } else if (found) {
|
720 | toReturn.push(iterable[counter]);
|
721 | }
|
722 | }
|
723 |
|
724 | return isArray ? toReturn.reverse() : toReturn.reverse().join('');
|
725 | }
|
726 |
|
727 | function dropRepeats(list) {
|
728 | if (!_isArray(list)) {
|
729 | throw new Error(`${list} is not a list`);
|
730 | }
|
731 |
|
732 | const toReturn = [];
|
733 | list.reduce((prev, current) => {
|
734 | if (!equals(prev, current)) {
|
735 | toReturn.push(current);
|
736 | }
|
737 |
|
738 | return current;
|
739 | }, undefined);
|
740 | return toReturn;
|
741 | }
|
742 |
|
743 | function dropRepeatsWith(predicate, list) {
|
744 | if (arguments.length === 1) {
|
745 | return _iterable => dropRepeatsWith(predicate, _iterable);
|
746 | }
|
747 |
|
748 | if (!_isArray(list)) {
|
749 | throw new Error(`${list} is not a list`);
|
750 | }
|
751 |
|
752 | const toReturn = [];
|
753 | list.reduce((prev, current) => {
|
754 | if (prev === undefined) {
|
755 | toReturn.push(current);
|
756 | return current;
|
757 | }
|
758 |
|
759 | if (!predicate(prev, current)) {
|
760 | toReturn.push(current);
|
761 | }
|
762 |
|
763 | return current;
|
764 | }, undefined);
|
765 | return toReturn;
|
766 | }
|
767 |
|
768 | function dropWhile(predicate, iterable) {
|
769 | if (arguments.length === 1) {
|
770 | return _iterable => dropWhile(predicate, _iterable);
|
771 | }
|
772 |
|
773 | const isArray = _isArray(iterable);
|
774 |
|
775 | if (!isArray && typeof iterable !== 'string') {
|
776 | throw new Error('`iterable` is neither list nor a string');
|
777 | }
|
778 |
|
779 | let flag = false;
|
780 | const holder = [];
|
781 | let counter = -1;
|
782 |
|
783 | while (counter++ < iterable.length - 1) {
|
784 | if (flag) {
|
785 | holder.push(iterable[counter]);
|
786 | } else if (!predicate(iterable[counter])) {
|
787 | if (!flag) flag = true;
|
788 | holder.push(iterable[counter]);
|
789 | }
|
790 | }
|
791 |
|
792 | return isArray ? holder : holder.join('');
|
793 | }
|
794 |
|
795 | function either(firstPredicate, secondPredicate) {
|
796 | if (arguments.length === 1) {
|
797 | return _secondPredicate => either(firstPredicate, _secondPredicate);
|
798 | }
|
799 |
|
800 | return (...input) => Boolean(firstPredicate(...input) || secondPredicate(...input));
|
801 | }
|
802 |
|
803 | function endsWith(target, str) {
|
804 | if (arguments.length === 1) return _str => endsWith(target, _str);
|
805 | return str.endsWith(target);
|
806 | }
|
807 |
|
808 | function eqPropsFn(prop, obj1, obj2) {
|
809 | if (!obj1 || !obj2) {
|
810 | throw new Error('wrong object inputs are passed to R.eqProps');
|
811 | }
|
812 |
|
813 | return equals(obj1[prop], obj2[prop]);
|
814 | }
|
815 |
|
816 | const eqProps = curry(eqPropsFn);
|
817 |
|
818 | function evolveArray(rules, list) {
|
819 | return mapArray((x, i) => {
|
820 | if (type(rules[i]) === 'Function') {
|
821 | return rules[i](x);
|
822 | }
|
823 |
|
824 | return x;
|
825 | }, list, true);
|
826 | }
|
827 | function evolveObject(rules, iterable) {
|
828 | return mapObject((x, prop) => {
|
829 | if (type(x) === 'Object') {
|
830 | const typeRule = type(rules[prop]);
|
831 |
|
832 | if (typeRule === 'Function') {
|
833 | return rules[prop](x);
|
834 | }
|
835 |
|
836 | if (typeRule === 'Object') {
|
837 | return evolve(rules[prop], x);
|
838 | }
|
839 |
|
840 | return x;
|
841 | }
|
842 |
|
843 | if (type(rules[prop]) === 'Function') {
|
844 | return rules[prop](x);
|
845 | }
|
846 |
|
847 | return x;
|
848 | }, iterable);
|
849 | }
|
850 | function evolve(rules, iterable) {
|
851 | if (arguments.length === 1) {
|
852 | return _iterable => evolve(rules, _iterable);
|
853 | }
|
854 |
|
855 | const rulesType = type(rules);
|
856 | const iterableType = type(iterable);
|
857 |
|
858 | if (iterableType !== rulesType) {
|
859 | throw new Error('iterableType !== rulesType');
|
860 | }
|
861 |
|
862 | if (!['Object', 'Array'].includes(rulesType)) {
|
863 | throw new Error(`'iterable' and 'rules' are from wrong type ${rulesType}`);
|
864 | }
|
865 |
|
866 | if (iterableType === 'Object') {
|
867 | return evolveObject(rules, iterable);
|
868 | }
|
869 |
|
870 | return evolveArray(rules, iterable);
|
871 | }
|
872 |
|
873 | function filterObject(fn, obj) {
|
874 | const willReturn = {};
|
875 |
|
876 | for (const prop in obj) {
|
877 | if (fn(obj[prop], prop, obj)) {
|
878 | willReturn[prop] = obj[prop];
|
879 | }
|
880 | }
|
881 |
|
882 | return willReturn;
|
883 | }
|
884 | function filterArray(predicate, list, indexed = false) {
|
885 | let index = 0;
|
886 | const len = list.length;
|
887 | const willReturn = [];
|
888 |
|
889 | while (index < len) {
|
890 | const predicateResult = indexed ? predicate(list[index], index) : predicate(list[index]);
|
891 |
|
892 | if (predicateResult) {
|
893 | willReturn.push(list[index]);
|
894 | }
|
895 |
|
896 | index++;
|
897 | }
|
898 |
|
899 | return willReturn;
|
900 | }
|
901 | function filter(predicate, iterable) {
|
902 | if (arguments.length === 1) {
|
903 | return _iterable => filter(predicate, _iterable);
|
904 | }
|
905 |
|
906 | if (!iterable) return [];
|
907 | if (_isArray(iterable)) return filterArray(predicate, iterable);
|
908 | return filterObject(predicate, iterable);
|
909 | }
|
910 |
|
911 | function find(predicate, list) {
|
912 | if (arguments.length === 1) return _list => find(predicate, _list);
|
913 | let index = 0;
|
914 | const len = list.length;
|
915 |
|
916 | while (index < len) {
|
917 | const x = list[index];
|
918 |
|
919 | if (predicate(x)) {
|
920 | return x;
|
921 | }
|
922 |
|
923 | index++;
|
924 | }
|
925 | }
|
926 |
|
927 | function findIndex(predicate, list) {
|
928 | if (arguments.length === 1) return _list => findIndex(predicate, _list);
|
929 | const len = list.length;
|
930 | let index = -1;
|
931 |
|
932 | while (++index < len) {
|
933 | if (predicate(list[index])) {
|
934 | return index;
|
935 | }
|
936 | }
|
937 |
|
938 | return -1;
|
939 | }
|
940 |
|
941 | function findLast(predicate, list) {
|
942 | if (arguments.length === 1) return _list => findLast(predicate, _list);
|
943 | let index = list.length;
|
944 |
|
945 | while (--index >= 0) {
|
946 | if (predicate(list[index])) {
|
947 | return list[index];
|
948 | }
|
949 | }
|
950 |
|
951 | return undefined;
|
952 | }
|
953 |
|
954 | function findLastIndex(fn, list) {
|
955 | if (arguments.length === 1) return _list => findLastIndex(fn, _list);
|
956 | let index = list.length;
|
957 |
|
958 | while (--index >= 0) {
|
959 | if (fn(list[index])) {
|
960 | return index;
|
961 | }
|
962 | }
|
963 |
|
964 | return -1;
|
965 | }
|
966 |
|
967 | function flatten(list, input) {
|
968 | const willReturn = input === undefined ? [] : input;
|
969 |
|
970 | for (let i = 0; i < list.length; i++) {
|
971 | if (_isArray(list[i])) {
|
972 | flatten(list[i], willReturn);
|
973 | } else {
|
974 | willReturn.push(list[i]);
|
975 | }
|
976 | }
|
977 |
|
978 | return willReturn;
|
979 | }
|
980 |
|
981 | function flipFn(fn) {
|
982 | return (...input) => {
|
983 | if (input.length === 1) {
|
984 | return holder => fn(holder, input[0]);
|
985 | } else if (input.length === 2) {
|
986 | return fn(input[1], input[0]);
|
987 | } else if (input.length === 3) {
|
988 | return fn(input[1], input[0], input[2]);
|
989 | } else if (input.length === 4) {
|
990 | return fn(input[1], input[0], input[2], input[3]);
|
991 | }
|
992 |
|
993 | throw new Error('R.flip doesn\'t work with arity > 4');
|
994 | };
|
995 | }
|
996 |
|
997 | function flip(fn) {
|
998 | return flipFn(fn);
|
999 | }
|
1000 |
|
1001 | function forEach(fn, list) {
|
1002 | if (arguments.length === 1) return _list => forEach(fn, _list);
|
1003 |
|
1004 | if (list === undefined) {
|
1005 | return;
|
1006 | }
|
1007 |
|
1008 | if (_isArray(list)) {
|
1009 | let index = 0;
|
1010 | const len = list.length;
|
1011 |
|
1012 | while (index < len) {
|
1013 | fn(list[index]);
|
1014 | index++;
|
1015 | }
|
1016 | } else {
|
1017 | let index = 0;
|
1018 |
|
1019 | const keys = _keys(list);
|
1020 |
|
1021 | const len = keys.length;
|
1022 |
|
1023 | while (index < len) {
|
1024 | const key = keys[index];
|
1025 | fn(list[key], key, list);
|
1026 | index++;
|
1027 | }
|
1028 | }
|
1029 |
|
1030 | return list;
|
1031 | }
|
1032 |
|
1033 | function fromPairs(listOfPairs) {
|
1034 | const toReturn = {};
|
1035 | listOfPairs.forEach(([prop, value]) => toReturn[prop] = value);
|
1036 | return toReturn;
|
1037 | }
|
1038 |
|
1039 | function groupBy(groupFn, list) {
|
1040 | if (arguments.length === 1) return _list => groupBy(groupFn, _list);
|
1041 | const result = {};
|
1042 |
|
1043 | for (let i = 0; i < list.length; i++) {
|
1044 | const item = list[i];
|
1045 | const key = groupFn(item);
|
1046 |
|
1047 | if (!result[key]) {
|
1048 | result[key] = [];
|
1049 | }
|
1050 |
|
1051 | result[key].push(item);
|
1052 | }
|
1053 |
|
1054 | return result;
|
1055 | }
|
1056 |
|
1057 | function groupWith(compareFn, list) {
|
1058 | if (!_isArray(list)) throw new TypeError('list.reduce is not a function');
|
1059 | const clone = list.slice();
|
1060 | if (list.length === 1) return [clone];
|
1061 | const toReturn = [];
|
1062 | let holder = [];
|
1063 | clone.reduce((prev, current, i) => {
|
1064 | if (i === 0) return current;
|
1065 | const okCompare = compareFn(prev, current);
|
1066 | const holderIsEmpty = holder.length === 0;
|
1067 | const lastCall = i === list.length - 1;
|
1068 |
|
1069 | if (okCompare) {
|
1070 | if (holderIsEmpty) holder.push(prev);
|
1071 | holder.push(current);
|
1072 | if (lastCall) toReturn.push(holder);
|
1073 | return current;
|
1074 | }
|
1075 |
|
1076 | if (holderIsEmpty) {
|
1077 | toReturn.push([prev]);
|
1078 | if (lastCall) toReturn.push([current]);
|
1079 | return current;
|
1080 | }
|
1081 |
|
1082 | toReturn.push(holder);
|
1083 | if (lastCall) toReturn.push([current]);
|
1084 | holder = [];
|
1085 | return current;
|
1086 | }, undefined);
|
1087 | return toReturn;
|
1088 | }
|
1089 |
|
1090 | function has(prop, obj) {
|
1091 | if (arguments.length === 1) return _obj => has(prop, _obj);
|
1092 | if (!obj) return false;
|
1093 | return obj.hasOwnProperty(prop);
|
1094 | }
|
1095 |
|
1096 | function path(pathInput, obj) {
|
1097 | if (arguments.length === 1) return _obj => path(pathInput, _obj);
|
1098 |
|
1099 | if (obj === null || obj === undefined) {
|
1100 | return undefined;
|
1101 | }
|
1102 |
|
1103 | let willReturn = obj;
|
1104 | let counter = 0;
|
1105 | const pathArrValue = typeof pathInput === 'string' ? pathInput.split('.') : pathInput;
|
1106 |
|
1107 | while (counter < pathArrValue.length) {
|
1108 | if (willReturn === null || willReturn === undefined) {
|
1109 | return undefined;
|
1110 | }
|
1111 |
|
1112 | if (willReturn[pathArrValue[counter]] === null) return undefined;
|
1113 | willReturn = willReturn[pathArrValue[counter]];
|
1114 | counter++;
|
1115 | }
|
1116 |
|
1117 | return willReturn;
|
1118 | }
|
1119 |
|
1120 | function hasPath(maybePath, obj) {
|
1121 | if (arguments.length === 1) {
|
1122 | return objHolder => hasPath(maybePath, objHolder);
|
1123 | }
|
1124 |
|
1125 | return path(maybePath, obj) !== undefined;
|
1126 | }
|
1127 |
|
1128 | function head(listOrString) {
|
1129 | if (typeof listOrString === 'string') return listOrString[0] || '';
|
1130 | return listOrString[0];
|
1131 | }
|
1132 |
|
1133 | function _objectIs(a, b) {
|
1134 | if (a === b) {
|
1135 | return a !== 0 || 1 / a === 1 / b;
|
1136 | }
|
1137 |
|
1138 | return a !== a && b !== b;
|
1139 | }
|
1140 | var _objectIs$1 = Object.is || _objectIs;
|
1141 |
|
1142 | function identical(a, b) {
|
1143 | if (arguments.length === 1) return _b => identical(a, _b);
|
1144 | return _objectIs$1(a, b);
|
1145 | }
|
1146 |
|
1147 | function identity(input) {
|
1148 | return input;
|
1149 | }
|
1150 |
|
1151 | function ifElseFn(condition, onTrue, onFalse) {
|
1152 | return (...input) => {
|
1153 | const conditionResult = typeof condition === 'boolean' ? condition : condition(...input);
|
1154 |
|
1155 | if (conditionResult === true) {
|
1156 | return onTrue(...input);
|
1157 | }
|
1158 |
|
1159 | return onFalse(...input);
|
1160 | };
|
1161 | }
|
1162 |
|
1163 | const ifElse = curry(ifElseFn);
|
1164 |
|
1165 | const inc = x => x + 1;
|
1166 |
|
1167 | function indexByPath(pathInput, list) {
|
1168 | const toReturn = {};
|
1169 |
|
1170 | for (let i = 0; i < list.length; i++) {
|
1171 | const item = list[i];
|
1172 | toReturn[path(pathInput, item)] = item;
|
1173 | }
|
1174 |
|
1175 | return toReturn;
|
1176 | }
|
1177 |
|
1178 | function indexBy(condition, list) {
|
1179 | if (arguments.length === 1) {
|
1180 | return _list => indexBy(condition, _list);
|
1181 | }
|
1182 |
|
1183 | if (typeof condition === 'string') {
|
1184 | return indexByPath(condition, list);
|
1185 | }
|
1186 |
|
1187 | const toReturn = {};
|
1188 |
|
1189 | for (let i = 0; i < list.length; i++) {
|
1190 | const item = list[i];
|
1191 | toReturn[condition(item)] = item;
|
1192 | }
|
1193 |
|
1194 | return toReturn;
|
1195 | }
|
1196 |
|
1197 | function indexOf(valueToFind, list) {
|
1198 | if (arguments.length === 1) {
|
1199 | return _list => indexOf(valueToFind, _list);
|
1200 | }
|
1201 |
|
1202 | let index = -1;
|
1203 | const {
|
1204 | length
|
1205 | } = list;
|
1206 |
|
1207 | while (++index < length) {
|
1208 | if (list[index] === valueToFind) {
|
1209 | return index;
|
1210 | }
|
1211 | }
|
1212 |
|
1213 | return -1;
|
1214 | }
|
1215 |
|
1216 | function baseSlice(array, start, end) {
|
1217 | let index = -1;
|
1218 | let {
|
1219 | length
|
1220 | } = array;
|
1221 | end = end > length ? length : end;
|
1222 |
|
1223 | if (end < 0) {
|
1224 | end += length;
|
1225 | }
|
1226 |
|
1227 | length = start > end ? 0 : end - start >>> 0;
|
1228 | start >>>= 0;
|
1229 | const result = Array(length);
|
1230 |
|
1231 | while (++index < length) {
|
1232 | result[index] = array[index + start];
|
1233 | }
|
1234 |
|
1235 | return result;
|
1236 | }
|
1237 |
|
1238 | function init(listOrString) {
|
1239 | if (typeof listOrString === 'string') return listOrString.slice(0, -1);
|
1240 | return listOrString.length ? baseSlice(listOrString, 0, -1) : [];
|
1241 | }
|
1242 |
|
1243 | function intersection(listA, listB) {
|
1244 | if (arguments.length === 1) return _list => intersection(listA, _list);
|
1245 | return filter(x => includes(x, listA), listB);
|
1246 | }
|
1247 |
|
1248 | function intersperse(separator, list) {
|
1249 | if (arguments.length === 1) return _list => intersperse(separator, _list);
|
1250 | let index = -1;
|
1251 | const len = list.length;
|
1252 | const willReturn = [];
|
1253 |
|
1254 | while (++index < len) {
|
1255 | if (index === len - 1) {
|
1256 | willReturn.push(list[index]);
|
1257 | } else {
|
1258 | willReturn.push(list[index], separator);
|
1259 | }
|
1260 | }
|
1261 |
|
1262 | return willReturn;
|
1263 | }
|
1264 |
|
1265 | function is(targetPrototype, x) {
|
1266 | if (arguments.length === 1) return _x => is(targetPrototype, _x);
|
1267 | return x != null && x.constructor === targetPrototype || x instanceof targetPrototype;
|
1268 | }
|
1269 |
|
1270 | function isEmpty(input) {
|
1271 | const inputType = type(input);
|
1272 | if (['Undefined', 'NaN', 'Number', 'Null'].includes(inputType)) return false;
|
1273 | if (!input) return true;
|
1274 |
|
1275 | if (inputType === 'Object') {
|
1276 | return Object.keys(input).length === 0;
|
1277 | }
|
1278 |
|
1279 | if (inputType === 'Array') {
|
1280 | return input.length === 0;
|
1281 | }
|
1282 |
|
1283 | return false;
|
1284 | }
|
1285 |
|
1286 | function isNil(x) {
|
1287 | return x === undefined || x === null;
|
1288 | }
|
1289 |
|
1290 | function join(glue, list) {
|
1291 | if (arguments.length === 1) return _list => join(glue, _list);
|
1292 | return list.join(glue);
|
1293 | }
|
1294 |
|
1295 | function keys(x) {
|
1296 | return Object.keys(x);
|
1297 | }
|
1298 |
|
1299 | function last(listOrString) {
|
1300 | if (typeof listOrString === 'string') {
|
1301 | return listOrString[listOrString.length - 1] || '';
|
1302 | }
|
1303 |
|
1304 | return listOrString[listOrString.length - 1];
|
1305 | }
|
1306 |
|
1307 | function lastIndexOf(target, list) {
|
1308 | if (arguments.length === 1) return _list => lastIndexOf(target, _list);
|
1309 | let index = list.length;
|
1310 |
|
1311 | while (--index > 0) {
|
1312 | if (equals(list[index], target)) {
|
1313 | return index;
|
1314 | }
|
1315 | }
|
1316 |
|
1317 | return -1;
|
1318 | }
|
1319 |
|
1320 | function length(x) {
|
1321 | if (!x && x !== '' || x.length === undefined) {
|
1322 | return NaN;
|
1323 | }
|
1324 |
|
1325 | return x.length;
|
1326 | }
|
1327 |
|
1328 | function lens(getter, setter) {
|
1329 | return function (functor) {
|
1330 | return function (target) {
|
1331 | return functor(getter(target)).map(focus => setter(focus, target));
|
1332 | };
|
1333 | };
|
1334 | }
|
1335 |
|
1336 | function nth(index, list) {
|
1337 | if (arguments.length === 1) return _list => nth(index, _list);
|
1338 | const idx = index < 0 ? list.length + index : index;
|
1339 | return Object.prototype.toString.call(list) === '[object String]' ? list.charAt(idx) : list[idx];
|
1340 | }
|
1341 |
|
1342 | function updateFn(index, newValue, list) {
|
1343 | const arrClone = list.slice();
|
1344 | return arrClone.fill(newValue, index, index + 1);
|
1345 | }
|
1346 |
|
1347 | const update = curry(updateFn);
|
1348 |
|
1349 | function lensIndex(index) {
|
1350 | return lens(nth(index), update(index));
|
1351 | }
|
1352 |
|
1353 | function lensPath(key) {
|
1354 | return lens(path(key), assocPath(key));
|
1355 | }
|
1356 |
|
1357 | function prop(propToFind, obj) {
|
1358 | if (arguments.length === 1) return _obj => prop(propToFind, _obj);
|
1359 | if (!obj) return undefined;
|
1360 | return obj[propToFind];
|
1361 | }
|
1362 |
|
1363 | function lensProp(key) {
|
1364 | return lens(prop(key), assoc(key));
|
1365 | }
|
1366 |
|
1367 | function match(pattern, input) {
|
1368 | if (arguments.length === 1) return _input => match(pattern, _input);
|
1369 | const willReturn = input.match(pattern);
|
1370 | return willReturn === null ? [] : willReturn;
|
1371 | }
|
1372 |
|
1373 | function mathMod(x, y) {
|
1374 | if (arguments.length === 1) return _y => mathMod(x, _y);
|
1375 | if (!_isInteger$1(x) || !_isInteger$1(y) || y < 1) return NaN;
|
1376 | return (x % y + y) % y;
|
1377 | }
|
1378 |
|
1379 | function maxByFn(compareFn, x, y) {
|
1380 | return compareFn(y) > compareFn(x) ? y : x;
|
1381 | }
|
1382 | const maxBy = curry(maxByFn);
|
1383 |
|
1384 | function sum(list) {
|
1385 | return list.reduce((prev, current) => prev + current, 0);
|
1386 | }
|
1387 |
|
1388 | function mean(list) {
|
1389 | return sum(list) / list.length;
|
1390 | }
|
1391 |
|
1392 | function median(list) {
|
1393 | const len = list.length;
|
1394 | if (len === 0) return NaN;
|
1395 | const width = 2 - len % 2;
|
1396 | const idx = (len - width) / 2;
|
1397 | return mean(Array.prototype.slice.call(list, 0).sort((a, b) => {
|
1398 | if (a === b) return 0;
|
1399 | return a < b ? -1 : 1;
|
1400 | }).slice(idx, idx + width));
|
1401 | }
|
1402 |
|
1403 | function merge(target, newProps) {
|
1404 | if (arguments.length === 1) return _newProps => merge(target, _newProps);
|
1405 | return Object.assign({}, target || {}, newProps || {});
|
1406 | }
|
1407 |
|
1408 | function mergeAll(arr) {
|
1409 | let willReturn = {};
|
1410 | map(val => {
|
1411 | willReturn = merge(willReturn, val);
|
1412 | }, arr);
|
1413 | return willReturn;
|
1414 | }
|
1415 |
|
1416 | function mergeDeepRight(target, source) {
|
1417 | if (arguments.length === 1) {
|
1418 | return sourceHolder => mergeDeepRight(target, sourceHolder);
|
1419 | }
|
1420 |
|
1421 | const willReturn = JSON.parse(JSON.stringify(target));
|
1422 | Object.keys(source).forEach(key => {
|
1423 | if (type(source[key]) === 'Object') {
|
1424 | if (type(target[key]) === 'Object') {
|
1425 | willReturn[key] = mergeDeepRight(target[key], source[key]);
|
1426 | } else {
|
1427 | willReturn[key] = source[key];
|
1428 | }
|
1429 | } else {
|
1430 | willReturn[key] = source[key];
|
1431 | }
|
1432 | });
|
1433 | return willReturn;
|
1434 | }
|
1435 |
|
1436 | function mergeLeft(x, y) {
|
1437 | if (arguments.length === 1) return _y => mergeLeft(x, _y);
|
1438 | return merge(y, x);
|
1439 | }
|
1440 |
|
1441 | function min(x, y) {
|
1442 | if (arguments.length === 1) return _y => min(x, _y);
|
1443 | return y < x ? y : x;
|
1444 | }
|
1445 |
|
1446 | function minByFn(compareFn, x, y) {
|
1447 | return compareFn(y) < compareFn(x) ? y : x;
|
1448 | }
|
1449 | const minBy = curry(minByFn);
|
1450 |
|
1451 | function modulo(x, y) {
|
1452 | if (arguments.length === 1) return _y => modulo(x, _y);
|
1453 | return x % y;
|
1454 | }
|
1455 |
|
1456 | function moveFn(fromIndex, toIndex, list) {
|
1457 | if (fromIndex < 0 || toIndex < 0) {
|
1458 | throw new Error('Rambda.move does not support negative indexes');
|
1459 | }
|
1460 |
|
1461 | if (fromIndex > list.length - 1 || toIndex > list.length - 1) return list;
|
1462 | const clone = list.slice();
|
1463 | clone[fromIndex] = list[toIndex];
|
1464 | clone[toIndex] = list[fromIndex];
|
1465 | return clone;
|
1466 | }
|
1467 |
|
1468 | const move = curry(moveFn);
|
1469 |
|
1470 | function multiply(x, y) {
|
1471 | if (arguments.length === 1) return _y => multiply(x, _y);
|
1472 | return x * y;
|
1473 | }
|
1474 |
|
1475 | function negate(x) {
|
1476 | return -x;
|
1477 | }
|
1478 |
|
1479 | function none(predicate, list) {
|
1480 | if (arguments.length === 1) return _list => none(predicate, _list);
|
1481 |
|
1482 | for (let i = 0; i < list.length; i++) {
|
1483 | if (!predicate(list[i])) return true;
|
1484 | }
|
1485 |
|
1486 | return false;
|
1487 | }
|
1488 |
|
1489 | function not(input) {
|
1490 | return !input;
|
1491 | }
|
1492 |
|
1493 | function objOf(key, value) {
|
1494 | if (arguments.length === 1) {
|
1495 | return _value => objOf(key, _value);
|
1496 | }
|
1497 |
|
1498 | return {
|
1499 | [key]: value
|
1500 | };
|
1501 | }
|
1502 |
|
1503 | function of(value) {
|
1504 | return [value];
|
1505 | }
|
1506 |
|
1507 | function omit(propsToOmit, obj) {
|
1508 | if (arguments.length === 1) return _obj => omit(propsToOmit, _obj);
|
1509 |
|
1510 | if (obj === null || obj === undefined) {
|
1511 | return undefined;
|
1512 | }
|
1513 |
|
1514 | const propsToOmitValue = typeof propsToOmit === 'string' ? propsToOmit.split(',') : propsToOmit;
|
1515 | const willReturn = {};
|
1516 |
|
1517 | for (const key in obj) {
|
1518 | if (!propsToOmitValue.includes(key)) {
|
1519 | willReturn[key] = obj[key];
|
1520 | }
|
1521 | }
|
1522 |
|
1523 | return willReturn;
|
1524 | }
|
1525 |
|
1526 | function onceFn(fn, context) {
|
1527 | let result;
|
1528 | return function () {
|
1529 | if (fn) {
|
1530 | result = fn.apply(context || this, arguments);
|
1531 | fn = null;
|
1532 | }
|
1533 |
|
1534 | return result;
|
1535 | };
|
1536 | }
|
1537 |
|
1538 | function once(fn, context) {
|
1539 | if (arguments.length === 1) {
|
1540 | const wrap = onceFn(fn, context);
|
1541 | return curry(wrap);
|
1542 | }
|
1543 |
|
1544 | return onceFn(fn, context);
|
1545 | }
|
1546 |
|
1547 | function or(a, b) {
|
1548 | if (arguments.length === 1) return _b => or(a, _b);
|
1549 | return a || b;
|
1550 | }
|
1551 |
|
1552 | const Identity = x => ({
|
1553 | x,
|
1554 | map: fn => Identity(fn(x))
|
1555 | });
|
1556 |
|
1557 | function overFn(lens, fn, object) {
|
1558 | return lens(x => Identity(fn(x)))(object).x;
|
1559 | }
|
1560 |
|
1561 | const over = curry(overFn);
|
1562 |
|
1563 | function partial(fn, ...args) {
|
1564 | const len = fn.length;
|
1565 | return (...rest) => {
|
1566 | if (args.length + rest.length >= len) {
|
1567 | return fn(...args, ...rest);
|
1568 | }
|
1569 |
|
1570 | return partial(fn, ...[...args, ...rest]);
|
1571 | };
|
1572 | }
|
1573 |
|
1574 | function partitionObject(predicate, iterable) {
|
1575 | const yes = {};
|
1576 | const no = {};
|
1577 | Object.entries(iterable).forEach(([prop, value]) => {
|
1578 | if (predicate(value, prop)) {
|
1579 | yes[prop] = value;
|
1580 | } else {
|
1581 | no[prop] = value;
|
1582 | }
|
1583 | });
|
1584 | return [yes, no];
|
1585 | }
|
1586 | function partitionArray(predicate, list) {
|
1587 | const yes = [];
|
1588 | const no = [];
|
1589 | let counter = -1;
|
1590 |
|
1591 | while (counter++ < list.length - 1) {
|
1592 | if (predicate(list[counter])) {
|
1593 | yes.push(list[counter]);
|
1594 | } else {
|
1595 | no.push(list[counter]);
|
1596 | }
|
1597 | }
|
1598 |
|
1599 | return [yes, no];
|
1600 | }
|
1601 | function partition(predicate, iterable) {
|
1602 | if (arguments.length === 1) {
|
1603 | return listHolder => partition(predicate, listHolder);
|
1604 | }
|
1605 |
|
1606 | if (!_isArray(iterable)) return partitionObject(predicate, iterable);
|
1607 | return partitionArray(predicate, iterable);
|
1608 | }
|
1609 |
|
1610 | function pathEqFn(pathToSearch, target, input) {
|
1611 | return equals(path(pathToSearch, input), target);
|
1612 | }
|
1613 |
|
1614 | const pathEq = curry(pathEqFn);
|
1615 |
|
1616 | function pathOrFn(defaultValue, list, obj) {
|
1617 | return defaultTo(defaultValue, path(list, obj));
|
1618 | }
|
1619 |
|
1620 | const pathOr = curry(pathOrFn);
|
1621 |
|
1622 | function paths(pathsToSearch, obj) {
|
1623 | if (arguments.length === 1) {
|
1624 | return _obj => paths(pathsToSearch, _obj);
|
1625 | }
|
1626 |
|
1627 | return pathsToSearch.map(singlePath => path(singlePath, obj));
|
1628 | }
|
1629 |
|
1630 | function pick(propsToPick, input) {
|
1631 | if (arguments.length === 1) return _input => pick(propsToPick, _input);
|
1632 |
|
1633 | if (input === null || input === undefined) {
|
1634 | return undefined;
|
1635 | }
|
1636 |
|
1637 | const keys = typeof propsToPick === 'string' ? propsToPick.split(',') : propsToPick;
|
1638 | const willReturn = {};
|
1639 | let counter = 0;
|
1640 |
|
1641 | while (counter < keys.length) {
|
1642 | if (keys[counter] in input) {
|
1643 | willReturn[keys[counter]] = input[keys[counter]];
|
1644 | }
|
1645 |
|
1646 | counter++;
|
1647 | }
|
1648 |
|
1649 | return willReturn;
|
1650 | }
|
1651 |
|
1652 | function pickAll(propsToPick, obj) {
|
1653 | if (arguments.length === 1) return _obj => pickAll(propsToPick, _obj);
|
1654 |
|
1655 | if (obj === null || obj === undefined) {
|
1656 | return undefined;
|
1657 | }
|
1658 |
|
1659 | const keysValue = typeof propsToPick === 'string' ? propsToPick.split(',') : propsToPick;
|
1660 | const willReturn = {};
|
1661 | let counter = 0;
|
1662 |
|
1663 | while (counter < keysValue.length) {
|
1664 | if (keysValue[counter] in obj) {
|
1665 | willReturn[keysValue[counter]] = obj[keysValue[counter]];
|
1666 | } else {
|
1667 | willReturn[keysValue[counter]] = undefined;
|
1668 | }
|
1669 |
|
1670 | counter++;
|
1671 | }
|
1672 |
|
1673 | return willReturn;
|
1674 | }
|
1675 |
|
1676 | function pipe(...fns) {
|
1677 | if (fns.length === 0) throw new Error('pipe requires at least one argument');
|
1678 | return (...args) => {
|
1679 | const list = fns.slice();
|
1680 |
|
1681 | if (list.length > 0) {
|
1682 | const fn = list.shift();
|
1683 | let result = fn(...args);
|
1684 |
|
1685 | while (list.length > 0) {
|
1686 | result = list.shift()(result);
|
1687 | }
|
1688 |
|
1689 | return result;
|
1690 | }
|
1691 | };
|
1692 | }
|
1693 |
|
1694 | function pluck(property, list) {
|
1695 | if (arguments.length === 1) return _list => pluck(property, _list);
|
1696 | const willReturn = [];
|
1697 | map(x => {
|
1698 | if (x[property] !== undefined) {
|
1699 | willReturn.push(x[property]);
|
1700 | }
|
1701 | }, list);
|
1702 | return willReturn;
|
1703 | }
|
1704 |
|
1705 | function prepend(x, input) {
|
1706 | if (arguments.length === 1) return _input => prepend(x, _input);
|
1707 | if (typeof input === 'string') return [x].concat(input.split(''));
|
1708 | return [x].concat(input);
|
1709 | }
|
1710 |
|
1711 | const product = reduce(multiply, 1);
|
1712 |
|
1713 | function propEqFn(propToFind, valueToMatch, obj) {
|
1714 | if (!obj) return false;
|
1715 | return obj[propToFind] === valueToMatch;
|
1716 | }
|
1717 |
|
1718 | const propEq = curry(propEqFn);
|
1719 |
|
1720 | function propIsFn(targetPrototype, property, obj) {
|
1721 | return is(targetPrototype, obj[property]);
|
1722 | }
|
1723 |
|
1724 | const propIs = curry(propIsFn);
|
1725 |
|
1726 | function propOrFn(defaultValue, property, obj) {
|
1727 | if (!obj) return defaultValue;
|
1728 | return defaultTo(defaultValue, obj[property]);
|
1729 | }
|
1730 |
|
1731 | const propOr = curry(propOrFn);
|
1732 |
|
1733 | function props(propsToPick, obj) {
|
1734 | if (arguments.length === 1) {
|
1735 | return _obj => props(propsToPick, _obj);
|
1736 | }
|
1737 |
|
1738 | if (!_isArray(propsToPick)) {
|
1739 | throw new Error('propsToPick is not a list');
|
1740 | }
|
1741 |
|
1742 | return mapArray(prop => obj[prop], propsToPick);
|
1743 | }
|
1744 |
|
1745 | function range(start, end) {
|
1746 | if (arguments.length === 1) return _end => range(start, _end);
|
1747 |
|
1748 | if (Number.isNaN(Number(start)) || Number.isNaN(Number(end))) {
|
1749 | throw new TypeError('Both arguments to range must be numbers');
|
1750 | }
|
1751 |
|
1752 | if (end < start) return [];
|
1753 | const len = end - start;
|
1754 | const willReturn = Array(len);
|
1755 |
|
1756 | for (let i = 0; i < len; i++) {
|
1757 | willReturn[i] = start + i;
|
1758 | }
|
1759 |
|
1760 | return willReturn;
|
1761 | }
|
1762 |
|
1763 | function reject(predicate, list) {
|
1764 | if (arguments.length === 1) return _list => reject(predicate, _list);
|
1765 | return filter(x => !predicate(x), list);
|
1766 | }
|
1767 |
|
1768 | function repeat(x, timesToRepeat) {
|
1769 | if (arguments.length === 1) {
|
1770 | return _timesToRepeat => repeat(x, _timesToRepeat);
|
1771 | }
|
1772 |
|
1773 | return Array(timesToRepeat).fill(x);
|
1774 | }
|
1775 |
|
1776 | function replaceFn(pattern, replacer, str) {
|
1777 | return str.replace(pattern, replacer);
|
1778 | }
|
1779 |
|
1780 | const replace = curry(replaceFn);
|
1781 |
|
1782 | function reverse(listOrString) {
|
1783 | if (typeof listOrString === 'string') {
|
1784 | return listOrString.split('').reverse().join('');
|
1785 | }
|
1786 |
|
1787 | const clone = listOrString.slice();
|
1788 | return clone.reverse();
|
1789 | }
|
1790 |
|
1791 | function setFn(lens, replacer, x) {
|
1792 | return over(lens, always(replacer), x);
|
1793 | }
|
1794 |
|
1795 | const set = curry(setFn);
|
1796 |
|
1797 | function sliceFn(from, to, list) {
|
1798 | return list.slice(from, to);
|
1799 | }
|
1800 |
|
1801 | const slice = curry(sliceFn);
|
1802 |
|
1803 | function sort(sortFn, list) {
|
1804 | if (arguments.length === 1) return _list => sort(sortFn, _list);
|
1805 | const clone = list.slice();
|
1806 | return clone.sort(sortFn);
|
1807 | }
|
1808 |
|
1809 | function sortBy(sortFn, list) {
|
1810 | if (arguments.length === 1) return _list => sortBy(sortFn, _list);
|
1811 | const clone = list.slice();
|
1812 | return clone.sort((a, b) => {
|
1813 | const aSortResult = sortFn(a);
|
1814 | const bSortResult = sortFn(b);
|
1815 | if (aSortResult === bSortResult) return 0;
|
1816 | return aSortResult < bSortResult ? -1 : 1;
|
1817 | });
|
1818 | }
|
1819 |
|
1820 | function split(separator, str) {
|
1821 | if (arguments.length === 1) return _str => split(separator, _str);
|
1822 | return str.split(separator);
|
1823 | }
|
1824 |
|
1825 | function maybe(ifRule, whenIf, whenElse) {
|
1826 | const whenIfInput = ifRule && type(whenIf) === 'Function' ? whenIf() : whenIf;
|
1827 | const whenElseInput = !ifRule && type(whenElse) === 'Function' ? whenElse() : whenElse;
|
1828 | return ifRule ? whenIfInput : whenElseInput;
|
1829 | }
|
1830 |
|
1831 | function take(howMany, listOrString) {
|
1832 | if (arguments.length === 1) return _listOrString => take(howMany, _listOrString);
|
1833 | if (howMany < 0) return listOrString.slice();
|
1834 | if (typeof listOrString === 'string') return listOrString.slice(0, howMany);
|
1835 | return baseSlice(listOrString, 0, howMany);
|
1836 | }
|
1837 |
|
1838 | function splitAt(index, input) {
|
1839 | if (arguments.length === 1) {
|
1840 | return _list => splitAt(index, _list);
|
1841 | }
|
1842 |
|
1843 | if (!input) throw new TypeError(`Cannot read property 'slice' of ${input}`);
|
1844 | if (!_isArray(input) && typeof input !== 'string') return [[], []];
|
1845 | const correctIndex = maybe(index < 0, input.length + index < 0 ? 0 : input.length + index, index);
|
1846 | return [take(correctIndex, input), drop(correctIndex, input)];
|
1847 | }
|
1848 |
|
1849 | function splitEvery(sliceLength, listOrString) {
|
1850 | if (arguments.length === 1) {
|
1851 | return _listOrString => splitEvery(sliceLength, _listOrString);
|
1852 | }
|
1853 |
|
1854 | if (sliceLength < 1) {
|
1855 | throw new Error('First argument to splitEvery must be a positive integer');
|
1856 | }
|
1857 |
|
1858 | const willReturn = [];
|
1859 | let counter = 0;
|
1860 |
|
1861 | while (counter < listOrString.length) {
|
1862 | willReturn.push(listOrString.slice(counter, counter += sliceLength));
|
1863 | }
|
1864 |
|
1865 | return willReturn;
|
1866 | }
|
1867 |
|
1868 | function splitWhen(predicate, input) {
|
1869 | if (arguments.length === 1) {
|
1870 | return _input => splitWhen(predicate, _input);
|
1871 | }
|
1872 |
|
1873 | if (!input) throw new TypeError(`Cannot read property 'length' of ${input}`);
|
1874 | const preFound = [];
|
1875 | const postFound = [];
|
1876 | let found = false;
|
1877 | let counter = -1;
|
1878 |
|
1879 | while (counter++ < input.length - 1) {
|
1880 | if (found) {
|
1881 | postFound.push(input[counter]);
|
1882 | } else if (predicate(input[counter])) {
|
1883 | postFound.push(input[counter]);
|
1884 | found = true;
|
1885 | } else {
|
1886 | preFound.push(input[counter]);
|
1887 | }
|
1888 | }
|
1889 |
|
1890 | return [preFound, postFound];
|
1891 | }
|
1892 |
|
1893 | function startsWith(target, str) {
|
1894 | if (arguments.length === 1) return _str => startsWith(target, _str);
|
1895 | return str.startsWith(target);
|
1896 | }
|
1897 |
|
1898 | function subtract(a, b) {
|
1899 | if (arguments.length === 1) return _b => subtract(a, _b);
|
1900 | return a - b;
|
1901 | }
|
1902 |
|
1903 | function symmetricDifference(x, y) {
|
1904 | if (arguments.length === 1) {
|
1905 | return _y => symmetricDifference(x, _y);
|
1906 | }
|
1907 |
|
1908 | return concat(filter(value => !includes(value, y), x), filter(value => !includes(value, x), y));
|
1909 | }
|
1910 |
|
1911 | function tail(listOrString) {
|
1912 | return drop(1, listOrString);
|
1913 | }
|
1914 |
|
1915 | function takeLast(howMany, listOrString) {
|
1916 | if (arguments.length === 1) return _listOrString => takeLast(howMany, _listOrString);
|
1917 | const len = listOrString.length;
|
1918 | if (howMany < 0) return listOrString.slice();
|
1919 | let numValue = howMany > len ? len : howMany;
|
1920 | if (typeof listOrString === 'string') return listOrString.slice(len - numValue);
|
1921 | numValue = len - numValue;
|
1922 | return baseSlice(listOrString, numValue, len);
|
1923 | }
|
1924 |
|
1925 | function takeLastWhile(predicate, input) {
|
1926 | if (arguments.length === 1) {
|
1927 | return _input => takeLastWhile(predicate, _input);
|
1928 | }
|
1929 |
|
1930 | if (input.length === 0) return input;
|
1931 | let found = false;
|
1932 | const toReturn = [];
|
1933 | let counter = input.length;
|
1934 |
|
1935 | while (!found || counter === 0) {
|
1936 | counter--;
|
1937 |
|
1938 | if (predicate(input[counter]) === false) {
|
1939 | found = true;
|
1940 | } else if (!found) {
|
1941 | toReturn.push(input[counter]);
|
1942 | }
|
1943 | }
|
1944 |
|
1945 | return _isArray(input) ? toReturn.reverse() : toReturn.reverse().join('');
|
1946 | }
|
1947 |
|
1948 | function takeWhile(predicate, iterable) {
|
1949 | if (arguments.length === 1) {
|
1950 | return _iterable => takeWhile(predicate, _iterable);
|
1951 | }
|
1952 |
|
1953 | const isArray = _isArray(iterable);
|
1954 |
|
1955 | if (!isArray && typeof iterable !== 'string') {
|
1956 | throw new Error('`iterable` is neither list nor a string');
|
1957 | }
|
1958 |
|
1959 | let flag = true;
|
1960 | const holder = [];
|
1961 | let counter = -1;
|
1962 |
|
1963 | while (counter++ < iterable.length - 1) {
|
1964 | if (!predicate(iterable[counter])) {
|
1965 | if (flag) flag = false;
|
1966 | } else if (flag) {
|
1967 | holder.push(iterable[counter]);
|
1968 | }
|
1969 | }
|
1970 | return isArray ? holder : holder.join('');
|
1971 | }
|
1972 |
|
1973 | function tap(fn, x) {
|
1974 | if (arguments.length === 1) return _x => tap(fn, _x);
|
1975 | fn(x);
|
1976 | return x;
|
1977 | }
|
1978 |
|
1979 | function test(pattern, str) {
|
1980 | if (arguments.length === 1) return _str => test(pattern, _str);
|
1981 |
|
1982 | if (typeof pattern === 'string') {
|
1983 | throw new TypeError(`‘test’ requires a value of type RegExp as its first argument; received "${pattern}"`);
|
1984 | }
|
1985 |
|
1986 | return str.search(pattern) !== -1;
|
1987 | }
|
1988 |
|
1989 | function times(fn, howMany) {
|
1990 | if (arguments.length === 1) return _howMany => times(fn, _howMany);
|
1991 |
|
1992 | if (!Number.isInteger(howMany) || howMany < 0) {
|
1993 | throw new RangeError('n must be an integer');
|
1994 | }
|
1995 |
|
1996 | return map(fn, range(0, howMany));
|
1997 | }
|
1998 |
|
1999 | function toLower(str) {
|
2000 | return str.toLowerCase();
|
2001 | }
|
2002 |
|
2003 | function toPairs(obj) {
|
2004 | return Object.entries(obj);
|
2005 | }
|
2006 |
|
2007 | function toString(x) {
|
2008 | return x.toString();
|
2009 | }
|
2010 |
|
2011 | function toUpper(str) {
|
2012 | return str.toUpperCase();
|
2013 | }
|
2014 |
|
2015 | function transpose(array) {
|
2016 | return array.reduce((acc, el) => {
|
2017 | el.forEach((nestedEl, i) => _isArray(acc[i]) ? acc[i].push(nestedEl) : acc.push([nestedEl]));
|
2018 | return acc;
|
2019 | }, []);
|
2020 | }
|
2021 |
|
2022 | function trim(str) {
|
2023 | return str.trim();
|
2024 | }
|
2025 |
|
2026 | function isFunction(fn) {
|
2027 | return ['Async', 'Function'].includes(type(fn));
|
2028 | }
|
2029 |
|
2030 | function tryCatch(fn, fallback) {
|
2031 | if (!isFunction(fn)) {
|
2032 | throw new Error(`R.tryCatch | fn '${fn}'`);
|
2033 | }
|
2034 |
|
2035 | const passFallback = isFunction(fallback);
|
2036 | return (...inputs) => {
|
2037 | try {
|
2038 | return fn(...inputs);
|
2039 | } catch (e) {
|
2040 | return passFallback ? fallback(e, ...inputs) : fallback;
|
2041 | }
|
2042 | };
|
2043 | }
|
2044 |
|
2045 | function union(x, y) {
|
2046 | if (arguments.length === 1) return _y => union(x, _y);
|
2047 | const toReturn = x.slice();
|
2048 | y.forEach(yInstance => {
|
2049 | if (!includes(yInstance, x)) toReturn.push(yInstance);
|
2050 | });
|
2051 | return toReturn;
|
2052 | }
|
2053 |
|
2054 | function uniqWith(predicate, list) {
|
2055 | if (arguments.length === 1) return _list => uniqWith(predicate, _list);
|
2056 | let index = -1;
|
2057 | const willReturn = [];
|
2058 |
|
2059 | while (++index < list.length) {
|
2060 | const value = list[index];
|
2061 | const flag = any(x => predicate(value, x), willReturn);
|
2062 |
|
2063 | if (!flag) {
|
2064 | willReturn.push(value);
|
2065 | }
|
2066 | }
|
2067 |
|
2068 | return willReturn;
|
2069 | }
|
2070 |
|
2071 | function unless(predicate, whenFalse) {
|
2072 | if (arguments.length === 1) {
|
2073 | return _whenFalse => unless(predicate, _whenFalse);
|
2074 | }
|
2075 |
|
2076 | return input => predicate(input) ? input : whenFalse(input);
|
2077 | }
|
2078 |
|
2079 | function values(obj) {
|
2080 | if (type(obj) !== 'Object') return [];
|
2081 | return Object.values(obj);
|
2082 | }
|
2083 |
|
2084 | const Const = x => ({
|
2085 | x,
|
2086 | map: fn => Const(x)
|
2087 | });
|
2088 |
|
2089 | function view(lens, target) {
|
2090 | if (arguments.length === 1) return _target => view(lens, _target);
|
2091 | return lens(Const)(target).x;
|
2092 | }
|
2093 |
|
2094 | function whenFn(predicate, whenTrueFn, input) {
|
2095 | if (!predicate(input)) return input;
|
2096 | return whenTrueFn(input);
|
2097 | }
|
2098 |
|
2099 | const when = curry(whenFn);
|
2100 |
|
2101 | function where(conditions, input) {
|
2102 | if (input === undefined) {
|
2103 | return _input => where(conditions, _input);
|
2104 | }
|
2105 |
|
2106 | let flag = true;
|
2107 |
|
2108 | for (const prop in conditions) {
|
2109 | const result = conditions[prop](input[prop]);
|
2110 |
|
2111 | if (flag && result === false) {
|
2112 | flag = false;
|
2113 | }
|
2114 | }
|
2115 |
|
2116 | return flag;
|
2117 | }
|
2118 |
|
2119 | function whereEq(condition, input) {
|
2120 | if (arguments.length === 1) {
|
2121 | return _input => whereEq(condition, _input);
|
2122 | }
|
2123 |
|
2124 | const result = filter((conditionValue, conditionProp) => equals(conditionValue, input[conditionProp]), condition);
|
2125 | return Object.keys(result).length === Object.keys(condition).length;
|
2126 | }
|
2127 |
|
2128 | function without(matchAgainst, source) {
|
2129 | if (source === undefined) {
|
2130 | return _source => without(matchAgainst, _source);
|
2131 | }
|
2132 |
|
2133 | return reduce((prev, current) => includesArray(current, matchAgainst) ? prev : prev.concat(current), [], source);
|
2134 | }
|
2135 |
|
2136 | function xor(a, b) {
|
2137 | if (arguments.length === 1) return _b => xor(a, _b);
|
2138 | return Boolean(a) && !b || Boolean(b) && !a;
|
2139 | }
|
2140 |
|
2141 | function zip(left, right) {
|
2142 | if (arguments.length === 1) return _right => zip(left, _right);
|
2143 | const result = [];
|
2144 | const length = Math.min(left.length, right.length);
|
2145 |
|
2146 | for (let i = 0; i < length; i++) {
|
2147 | result[i] = [left[i], right[i]];
|
2148 | }
|
2149 |
|
2150 | return result;
|
2151 | }
|
2152 |
|
2153 | function zipObj(keys, values) {
|
2154 | if (arguments.length === 1) return yHolder => zipObj(keys, yHolder);
|
2155 | return take(values.length, keys).reduce((prev, xInstance, i) => {
|
2156 | prev[xInstance] = values[i];
|
2157 | return prev;
|
2158 | }, {});
|
2159 | }
|
2160 |
|
2161 | function zipWithFn(fn, x, y) {
|
2162 | return take(x.length > y.length ? y.length : x.length, x).map((xInstance, i) => fn(xInstance, y[i]));
|
2163 | }
|
2164 |
|
2165 | const zipWith = curry(zipWithFn);
|
2166 |
|
2167 | export { F, T, add, adjust, all, allPass, always, and, any, anyPass, append, applySpec, assoc, assocPath, both, chain, clamp, clone, complement, compose, concat, cond, converge, curry, curryN, dec, defaultTo, difference, dissoc, divide, drop, dropLast, dropLastWhile, dropRepeats, dropRepeatsWith, dropWhile, either, endsWith, eqProps, equals, evolve, evolveArray, evolveObject, filter, filterArray, filterObject, find, findIndex, findLast, findLastIndex, flatten, flip, forEach, fromPairs, groupBy, groupWith, has, hasPath, head, identical, identity, ifElse, inc, includes, includesArray, indexBy, indexOf, init, intersection, intersperse, is, isEmpty, isNil, join, keys, last, lastIndexOf, length, lens, lensIndex, lensPath, lensProp, map, mapArray, mapObject, match, mathMod, max, maxBy, maxByFn, mean, median, merge, mergeAll, mergeDeepRight, mergeLeft, min, minBy, minByFn, modulo, move, multiply, negate, none, not, nth, objOf, of, omit, once, or, over, partial, partition, partitionArray, partitionObject, path, pathEq, pathOr, paths, pick, pickAll, pipe, pluck, prepend, product, prop, propEq, propIs, propOr, props, range, reduce, reject, repeat, replace, reverse, set, slice, sort, sortBy, split, splitAt, splitEvery, splitWhen, startsWith, subtract, sum, symmetricDifference, tail, take, takeLast, takeLastWhile, takeWhile, tap, test, times, toLower, toPairs, toString, toUpper, transpose, trim, tryCatch, type, union, uniq, uniqWith, unless, update, values, view, when, where, whereEq, without, xor, zip, zipObj, zipWith };
|
2168 |
|
\ | No newline at end of file |