rambda 7.1.3 → 7.2.1

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