rambda 10.0.0-alpha.0 → 10.0.0-beta.3
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.
- package/CHANGELOG.md +125 -16
- package/README.md +8035 -3592
- package/dist/{rambda.esm.js → rambda.cjs} +800 -385
- package/dist/rambda.js +673 -486
- package/dist/rambda.umd.js +701 -388
- package/immutable.d.ts +896 -345
- package/index.d.ts +896 -345
- package/package.json +22 -15
- package/rambda.js +23 -2
- package/src/addProp.js +3 -0
- package/src/addPropToObjects.js +14 -0
- package/src/append.js +5 -5
- package/src/ascend.js +16 -0
- package/src/compact.js +12 -0
- package/src/concat.js +1 -1
- package/src/count.js +7 -7
- package/src/countBy.js +12 -12
- package/src/createObjectFromKeys.js +10 -0
- package/src/defaultTo.js +2 -6
- package/src/descend.js +10 -0
- package/src/drop.js +2 -6
- package/src/dropLast.js +1 -3
- package/src/eqProps.js +1 -2
- package/src/equals.js +2 -2
- package/src/evolve.js +2 -23
- package/src/filter.js +14 -14
- package/src/find.js +10 -10
- package/src/findIndex.js +9 -9
- package/src/findLast.js +8 -8
- package/src/findLastIndex.js +8 -8
- package/src/findNth.js +16 -0
- package/src/flattenObject.js +76 -0
- package/src/groupBy.js +14 -13
- package/src/includes.js +12 -13
- package/src/interpolate.js +29 -0
- package/src/intersection.js +1 -1
- package/src/intersperse.js +12 -12
- package/src/join.js +1 -1
- package/src/map.js +13 -9
- package/src/mapAsync.js +3 -3
- package/src/mapKeys.js +11 -0
- package/src/mapObjectAsync.js +9 -9
- package/src/mapParallelAsync.js +3 -0
- package/src/match.js +5 -5
- package/src/{replaceItemAtIndex.js → modifyItemAtIndex.js} +1 -1
- package/src/modifyProp.js +20 -0
- package/src/objectIncludes.js +12 -0
- package/src/partition.js +13 -37
- package/src/partitionObject.js +15 -0
- package/src/path.js +24 -26
- package/src/pathSatisfies.js +5 -0
- package/src/permutations.js +40 -0
- package/src/pipeAsync.js +7 -6
- package/src/pluck.js +9 -9
- package/src/prepend.js +1 -1
- package/src/propOr.js +1 -1
- package/src/propSatisfies.js +1 -3
- package/src/range.js +29 -13
- package/src/reject.js +1 -1
- package/src/rejectObject.js +13 -0
- package/src/shuffle.js +13 -0
- package/src/sort.js +1 -1
- package/src/sortBy.js +20 -9
- package/src/sortByDescending.js +5 -0
- package/src/sortByPath.js +6 -0
- package/src/sortByPathDescending.js +6 -0
- package/src/sortObject.js +15 -0
- package/src/sortWith.js +8 -8
- package/src/split.js +2 -2
- package/src/splitEvery.js +11 -11
- package/src/takeLastWhile.js +18 -18
- package/src/tap.js +4 -4
- package/src/test.js +1 -1
- package/src/uniqBy.js +4 -4
- package/src/uniqWith.js +10 -10
- package/src/modifyPath.js +0 -30
|
@@ -1,3 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function addProp(key, value) {
|
|
4
|
+
return obj => ({ ...obj, [key]: value })
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function mapFn(
|
|
8
|
+
fn, list
|
|
9
|
+
){
|
|
10
|
+
let index = 0;
|
|
11
|
+
const willReturn = Array(list.length);
|
|
12
|
+
while (index < list.length) {
|
|
13
|
+
willReturn[index] = fn(list[index], index);
|
|
14
|
+
index++;
|
|
15
|
+
}
|
|
16
|
+
return willReturn
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function map(fn) {
|
|
20
|
+
return list => mapFn(fn, list)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function addPropToObjects (
|
|
24
|
+
property,
|
|
25
|
+
fn
|
|
26
|
+
){
|
|
27
|
+
return listOfObjects => mapFn(
|
|
28
|
+
(obj) => ({
|
|
29
|
+
...(obj),
|
|
30
|
+
[property]: fn(obj)
|
|
31
|
+
}),
|
|
32
|
+
listOfObjects
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
1
36
|
function all(predicate) {
|
|
2
37
|
return list => {
|
|
3
38
|
for (let i = 0; i < list.length; i++) {
|
|
@@ -52,15 +87,32 @@ function anyPass(predicates) {
|
|
|
52
87
|
}
|
|
53
88
|
}
|
|
54
89
|
|
|
55
|
-
const cloneList = list => Array.prototype.slice.call(list);
|
|
90
|
+
const cloneList$1 = list => Array.prototype.slice.call(list);
|
|
56
91
|
|
|
57
92
|
function append(x) {
|
|
58
|
-
return list=> {
|
|
59
|
-
|
|
60
|
-
|
|
93
|
+
return list => {
|
|
94
|
+
const clone = cloneList$1(list);
|
|
95
|
+
clone.push(x);
|
|
61
96
|
|
|
62
|
-
|
|
63
|
-
|
|
97
|
+
return clone
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function createCompareFunction(a, b, winner, loser) {
|
|
102
|
+
if (a === b) {
|
|
103
|
+
return 0
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return a < b ? winner : loser
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function ascend(getFunction) {
|
|
110
|
+
return (a, b) => {
|
|
111
|
+
const aValue = getFunction(a);
|
|
112
|
+
const bValue = getFunction(b);
|
|
113
|
+
|
|
114
|
+
return createCompareFunction(aValue, bValue, -1, 1)
|
|
115
|
+
}
|
|
64
116
|
}
|
|
65
117
|
|
|
66
118
|
function checkObjectWithSpec(conditions) {
|
|
@@ -80,67 +132,125 @@ function checkObjectWithSpec(conditions) {
|
|
|
80
132
|
}
|
|
81
133
|
}
|
|
82
134
|
|
|
135
|
+
const { isArray } = Array;
|
|
136
|
+
|
|
137
|
+
function filter(predicate) {
|
|
138
|
+
return list => {
|
|
139
|
+
if (!list) {
|
|
140
|
+
throw new Error('Incorrect iterable input')
|
|
141
|
+
}
|
|
142
|
+
let index = 0;
|
|
143
|
+
const len = list.length;
|
|
144
|
+
const willReturn = [];
|
|
145
|
+
|
|
146
|
+
while (index < len) {
|
|
147
|
+
if (predicate(list[index], index)) {
|
|
148
|
+
willReturn.push(list[index]);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
index++;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return willReturn
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function reject(predicate) {
|
|
159
|
+
return list => filter(x => !predicate(x))(list)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function rejectObject(predicate) {
|
|
163
|
+
return obj => {
|
|
164
|
+
const willReturn = {};
|
|
165
|
+
|
|
166
|
+
for (const prop in obj) {
|
|
167
|
+
if (!predicate(obj[prop], prop, obj)) {
|
|
168
|
+
willReturn[prop] = obj[prop];
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return willReturn
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const isNullOrUndefined = x => x === null || x === undefined;
|
|
177
|
+
|
|
178
|
+
function compact(input){
|
|
179
|
+
if(isArray(input)){
|
|
180
|
+
return reject(isNullOrUndefined)(input)
|
|
181
|
+
}
|
|
182
|
+
return rejectObject(isNullOrUndefined)(input)
|
|
183
|
+
}
|
|
184
|
+
|
|
83
185
|
function complement(fn) {
|
|
84
186
|
return (...input) => !fn(...input)
|
|
85
187
|
}
|
|
86
188
|
|
|
87
189
|
function concat(x) {
|
|
88
|
-
return y => typeof x === 'string' ? `${x}${y}` : [...x, ...y]
|
|
190
|
+
return y => (typeof x === 'string' ? `${x}${y}` : [...x, ...y])
|
|
89
191
|
}
|
|
90
192
|
|
|
91
|
-
|
|
193
|
+
function count(predicate) {
|
|
194
|
+
return list => {
|
|
195
|
+
if (!isArray(list)) {
|
|
196
|
+
return 0
|
|
197
|
+
}
|
|
92
198
|
|
|
93
|
-
|
|
94
|
-
return list => {
|
|
95
|
-
if (!isArray(list)) {
|
|
96
|
-
return 0
|
|
199
|
+
return list.filter(x => predicate(x)).length
|
|
97
200
|
}
|
|
98
|
-
|
|
99
|
-
return list.filter(x => predicate(x)).length
|
|
100
|
-
}
|
|
101
201
|
}
|
|
102
202
|
|
|
103
203
|
function countBy(fn) {
|
|
104
|
-
|
|
105
|
-
|
|
204
|
+
return list => {
|
|
205
|
+
const willReturn = {};
|
|
106
206
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
207
|
+
list.forEach(item => {
|
|
208
|
+
const key = fn(item);
|
|
209
|
+
if (!willReturn[key]) {
|
|
210
|
+
willReturn[key] = 1;
|
|
211
|
+
} else {
|
|
212
|
+
willReturn[key]++;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
115
215
|
|
|
116
|
-
|
|
216
|
+
return willReturn
|
|
217
|
+
}
|
|
117
218
|
}
|
|
219
|
+
|
|
220
|
+
function createObjectFromKeys(keys) {
|
|
221
|
+
return fn => {
|
|
222
|
+
const result = {};
|
|
223
|
+
keys.forEach((key, index) => {
|
|
224
|
+
result[key] = fn(key, index);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
return result
|
|
228
|
+
}
|
|
118
229
|
}
|
|
119
230
|
|
|
120
231
|
function isFalsy(input) {
|
|
121
232
|
return input === undefined || input === null || Number.isNaN(input) === true
|
|
122
233
|
}
|
|
123
234
|
|
|
124
|
-
function defaultTo(defaultArgument
|
|
125
|
-
|
|
126
|
-
return _input => defaultTo(defaultArgument, _input)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return isFalsy(input) ? defaultArgument : input
|
|
235
|
+
function defaultTo(defaultArgument) {
|
|
236
|
+
return input => isFalsy(input) ? defaultArgument : input
|
|
130
237
|
}
|
|
131
238
|
|
|
132
|
-
function
|
|
133
|
-
|
|
134
|
-
|
|
239
|
+
function descend(getFunction) {
|
|
240
|
+
return (a, b) => {
|
|
241
|
+
const aValue = getFunction(a);
|
|
242
|
+
const bValue = getFunction(b);
|
|
243
|
+
|
|
244
|
+
return createCompareFunction(aValue, bValue, 1, -1)
|
|
135
245
|
}
|
|
246
|
+
}
|
|
136
247
|
|
|
137
|
-
|
|
248
|
+
function drop(howManyToDrop, ) {
|
|
249
|
+
return list => list.slice(howManyToDrop > 0 ? howManyToDrop : 0)
|
|
138
250
|
}
|
|
139
251
|
|
|
140
252
|
function dropLast(numberItems) {
|
|
141
|
-
|
|
142
|
-
? list.slice(0, -numberItems)
|
|
143
|
-
: list.slice()
|
|
253
|
+
return list => (numberItems > 0 ? list.slice(0, -numberItems) : list.slice())
|
|
144
254
|
}
|
|
145
255
|
|
|
146
256
|
function dropLastWhile(predicate) {
|
|
@@ -300,7 +410,7 @@ function parseRegex(maybeRegex) {
|
|
|
300
410
|
}
|
|
301
411
|
|
|
302
412
|
function equalsFn(a, b) {
|
|
303
|
-
|
|
413
|
+
if (Object.is(a, b)) {
|
|
304
414
|
return true
|
|
305
415
|
}
|
|
306
416
|
|
|
@@ -409,19 +519,15 @@ function equalsFn(a, b) {
|
|
|
409
519
|
return false
|
|
410
520
|
}
|
|
411
521
|
function equals(a) {
|
|
412
|
-
|
|
522
|
+
return b => equalsFn(a, b)
|
|
413
523
|
}
|
|
414
524
|
|
|
415
525
|
function eqBy(fn, a) {
|
|
416
526
|
return b => equalsFn(fn(a), fn(b))
|
|
417
527
|
}
|
|
418
528
|
|
|
419
|
-
function prop(searchProperty) {
|
|
420
|
-
return obj => (obj ? obj[searchProperty] : undefined)
|
|
421
|
-
}
|
|
422
|
-
|
|
423
529
|
function eqProps(property, objA) {
|
|
424
|
-
return objB => equalsFn(
|
|
530
|
+
return objB => equalsFn( objA[property], objB[property] )
|
|
425
531
|
}
|
|
426
532
|
|
|
427
533
|
const { keys } = Object;
|
|
@@ -443,73 +549,30 @@ function mapObject(fn) {
|
|
|
443
549
|
}
|
|
444
550
|
}
|
|
445
551
|
|
|
446
|
-
function evolveFn(rules, obj) {
|
|
447
|
-
return mapObject((x, prop) => {
|
|
448
|
-
if (type(x) === 'Object') {
|
|
449
|
-
const typeRule = type(rules[prop]);
|
|
450
|
-
if (typeRule === 'Function') {
|
|
451
|
-
return rules[prop](x)
|
|
452
|
-
}
|
|
453
|
-
if (typeRule === 'Object') {
|
|
454
|
-
return evolveFn(rules[prop], x)
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
return x
|
|
458
|
-
}
|
|
459
|
-
if (type(rules[prop]) === 'Function') {
|
|
460
|
-
return rules[prop](x)
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
return x
|
|
464
|
-
})(obj)
|
|
465
|
-
}
|
|
466
|
-
|
|
467
552
|
function evolve(rules) {
|
|
468
|
-
return
|
|
469
|
-
|
|
553
|
+
return mapObject((x, prop) => type(rules[prop]) === 'Function' ? rules[prop](x): x)
|
|
554
|
+
}
|
|
470
555
|
|
|
471
556
|
function includes(valueToFind) {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
}
|
|
557
|
+
return iterable => {
|
|
558
|
+
if (typeof iterable === 'string') {
|
|
559
|
+
return iterable.includes(valueToFind)
|
|
560
|
+
}
|
|
561
|
+
if (!iterable) {
|
|
562
|
+
throw new TypeError(`Cannot read property \'indexOf\' of ${iterable}`)
|
|
563
|
+
}
|
|
564
|
+
if (!isArray(iterable)) {
|
|
565
|
+
return false
|
|
566
|
+
}
|
|
483
567
|
|
|
484
|
-
|
|
485
|
-
}
|
|
568
|
+
return _indexOf(valueToFind, iterable) > -1
|
|
569
|
+
}
|
|
486
570
|
}
|
|
487
571
|
|
|
488
572
|
function excludes(valueToFind) {
|
|
489
573
|
return iterable => !includes(valueToFind)(iterable)
|
|
490
574
|
}
|
|
491
575
|
|
|
492
|
-
function filter(predicate) {
|
|
493
|
-
return list => {
|
|
494
|
-
if (!list) {
|
|
495
|
-
throw new Error('Incorrect iterable input')
|
|
496
|
-
}
|
|
497
|
-
let index = 0;
|
|
498
|
-
const len = list.length;
|
|
499
|
-
const willReturn = [];
|
|
500
|
-
|
|
501
|
-
while (index < len) {
|
|
502
|
-
if (predicate(list[index], index)) {
|
|
503
|
-
willReturn.push(list[index]);
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
index++;
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
return willReturn
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
|
|
513
576
|
function filterObject(predicate) {
|
|
514
577
|
return obj => {
|
|
515
578
|
const willReturn = {};
|
|
@@ -525,62 +588,79 @@ function filterObject(predicate) {
|
|
|
525
588
|
}
|
|
526
589
|
|
|
527
590
|
function find(predicate) {
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
591
|
+
return list => {
|
|
592
|
+
let index = 0;
|
|
593
|
+
const len = list.length;
|
|
531
594
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
595
|
+
while (index < len) {
|
|
596
|
+
const x = list[index];
|
|
597
|
+
if (predicate(x)) {
|
|
598
|
+
return x
|
|
599
|
+
}
|
|
537
600
|
|
|
538
|
-
|
|
601
|
+
index++;
|
|
602
|
+
}
|
|
539
603
|
}
|
|
540
604
|
}
|
|
541
|
-
}
|
|
542
605
|
|
|
543
606
|
function findIndex(predicate) {
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
607
|
+
return list => {
|
|
608
|
+
const len = list.length;
|
|
609
|
+
let index = -1;
|
|
547
610
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
611
|
+
while (++index < len) {
|
|
612
|
+
if (predicate(list[index])) {
|
|
613
|
+
return index
|
|
614
|
+
}
|
|
551
615
|
}
|
|
552
|
-
}
|
|
553
616
|
|
|
554
|
-
|
|
555
|
-
}
|
|
617
|
+
return -1
|
|
618
|
+
}
|
|
556
619
|
}
|
|
557
620
|
|
|
558
621
|
function findLast(predicate) {
|
|
559
|
-
|
|
560
|
-
|
|
622
|
+
return list => {
|
|
623
|
+
let index = list.length;
|
|
561
624
|
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
625
|
+
while (--index >= 0) {
|
|
626
|
+
if (predicate(list[index])) {
|
|
627
|
+
return list[index]
|
|
628
|
+
}
|
|
565
629
|
}
|
|
566
|
-
}
|
|
567
630
|
|
|
568
|
-
|
|
569
|
-
}
|
|
631
|
+
return undefined
|
|
632
|
+
}
|
|
570
633
|
}
|
|
571
634
|
|
|
572
635
|
function findLastIndex(fn) {
|
|
573
|
-
|
|
574
|
-
|
|
636
|
+
return list => {
|
|
637
|
+
let index = list.length;
|
|
575
638
|
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
639
|
+
while (--index >= 0) {
|
|
640
|
+
if (fn(list[index])) {
|
|
641
|
+
return index
|
|
642
|
+
}
|
|
579
643
|
}
|
|
580
|
-
}
|
|
581
644
|
|
|
582
|
-
|
|
645
|
+
return -1
|
|
646
|
+
}
|
|
583
647
|
}
|
|
648
|
+
|
|
649
|
+
function findNth(predicate, nth) {
|
|
650
|
+
return list => {
|
|
651
|
+
let index = 0;
|
|
652
|
+
const len = list.length;
|
|
653
|
+
|
|
654
|
+
while (index < len) {
|
|
655
|
+
const x = list[index];
|
|
656
|
+
if (predicate(x)) {
|
|
657
|
+
if (nth === 0) return x
|
|
658
|
+
nth--;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
index++;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
584
664
|
}
|
|
585
665
|
|
|
586
666
|
function flatMap(fn) {
|
|
@@ -601,24 +681,100 @@ function flatten(list, input) {
|
|
|
601
681
|
return willReturn
|
|
602
682
|
}
|
|
603
683
|
|
|
604
|
-
function
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
684
|
+
function flattenObjectHelper(obj, accumulator = []){
|
|
685
|
+
const willReturn = {};
|
|
686
|
+
Object.keys(obj).forEach(key => {
|
|
687
|
+
const typeIs = type(obj[ key ]);
|
|
688
|
+
if (typeIs === 'Object'){
|
|
689
|
+
const [ flatResultValue, flatResultPath ] = flattenObjectHelper(obj[ key ],
|
|
690
|
+
[ ...accumulator, key ]);
|
|
691
|
+
willReturn[ flatResultPath.join('.') ] = flatResultValue;
|
|
608
692
|
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
693
|
+
return
|
|
694
|
+
} else if (accumulator.length > 0){
|
|
695
|
+
const finalKey = [ ...accumulator, key ].join('.');
|
|
696
|
+
willReturn[ finalKey ] = obj[ key ];
|
|
613
697
|
|
|
614
|
-
|
|
615
|
-
result[key] = [];
|
|
698
|
+
return
|
|
616
699
|
}
|
|
700
|
+
willReturn[ key ] = obj[ key ];
|
|
701
|
+
});
|
|
702
|
+
if (accumulator.length > 0) return [ willReturn, accumulator ]
|
|
617
703
|
|
|
618
|
-
|
|
619
|
-
|
|
704
|
+
return willReturn
|
|
705
|
+
}
|
|
620
706
|
|
|
621
|
-
|
|
707
|
+
function transformFlatObject(obj){
|
|
708
|
+
const willReturn = {};
|
|
709
|
+
|
|
710
|
+
const transformFlatObjectFn = objLocal => {
|
|
711
|
+
const willReturnLocal = {};
|
|
712
|
+
Object.keys(objLocal).forEach(key => {
|
|
713
|
+
const typeIs = type(objLocal[ key ]);
|
|
714
|
+
if (typeIs === 'Object'){
|
|
715
|
+
transformFlatObjectFn(objLocal[ key ]);
|
|
716
|
+
|
|
717
|
+
return
|
|
718
|
+
}
|
|
719
|
+
willReturnLocal[ key ] = objLocal[ key ];
|
|
720
|
+
willReturn[ key ] = objLocal[ key ];
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
return willReturnLocal
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
Object.keys(obj).forEach(key => {
|
|
727
|
+
const typeIs = type(obj[ key ]);
|
|
728
|
+
if (typeIs === 'Object'){
|
|
729
|
+
transformFlatObjectFn(obj[ key ]);
|
|
730
|
+
|
|
731
|
+
return
|
|
732
|
+
}
|
|
733
|
+
willReturn[ key ] = obj[ key ];
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
return willReturn
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
function flattenObject(obj){
|
|
740
|
+
const willReturn = {};
|
|
741
|
+
|
|
742
|
+
Object.keys(obj).forEach(key => {
|
|
743
|
+
const typeIs = type(obj[ key ]);
|
|
744
|
+
if (typeIs === 'Object'){
|
|
745
|
+
const flatObject = flattenObjectHelper(obj[ key ]);
|
|
746
|
+
const transformed = transformFlatObject(flatObject);
|
|
747
|
+
|
|
748
|
+
Object.keys(transformed).forEach(keyTransformed => {
|
|
749
|
+
willReturn[ `${ key }.${ keyTransformed }` ] = transformed[ keyTransformed ];
|
|
750
|
+
});
|
|
751
|
+
} else {
|
|
752
|
+
willReturn[ key ] = obj[ key ];
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
|
|
756
|
+
return willReturn
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
function groupByFallback(groupFn, list) {
|
|
760
|
+
const result = {};
|
|
761
|
+
for (let i = 0; i < list.length; i++) {
|
|
762
|
+
const item = list[i];
|
|
763
|
+
const key = groupFn(item);
|
|
764
|
+
|
|
765
|
+
if (!result[key]) {
|
|
766
|
+
result[key] = [];
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
result[key].push(item);
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
return result
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
|
|
776
|
+
function groupBy(groupFn) {
|
|
777
|
+
return iterable => Object.groupBy ? Object.groupBy(iterable,groupFn) : groupByFallback(groupFn, iterable)
|
|
622
778
|
}
|
|
623
779
|
|
|
624
780
|
function head(listOrString) {
|
|
@@ -695,30 +851,60 @@ function innerJoin(pred, xs) {
|
|
|
695
851
|
return ys => _filter(x => _includesWith(pred, x, ys), xs)
|
|
696
852
|
}
|
|
697
853
|
|
|
854
|
+
const getOccurrences = input => input.match(/{{\s*.+?\s*}}/g);
|
|
855
|
+
const getOccurrenceProp = occurrence => occurrence.replace(/{{\s*|\s*}}/g, '');
|
|
856
|
+
|
|
857
|
+
const replace$1 = ({ inputHolder, prop, replacer }) => {
|
|
858
|
+
const regexBase = `{{${prop}}}`;
|
|
859
|
+
const regex = new RegExp(regexBase, 'g');
|
|
860
|
+
return inputHolder.replace(regex, replacer)
|
|
861
|
+
};
|
|
862
|
+
|
|
863
|
+
function interpolate(input) {
|
|
864
|
+
return templateInput => {
|
|
865
|
+
const occurrences = getOccurrences(input);
|
|
866
|
+
if (occurrences === null) {
|
|
867
|
+
return input
|
|
868
|
+
}
|
|
869
|
+
let inputHolder = input;
|
|
870
|
+
|
|
871
|
+
for (const occurrence of occurrences) {
|
|
872
|
+
const prop = getOccurrenceProp(occurrence);
|
|
873
|
+
inputHolder = replace$1({
|
|
874
|
+
inputHolder,
|
|
875
|
+
prop,
|
|
876
|
+
replacer: templateInput[prop],
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
return inputHolder
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
|
|
698
884
|
function intersection(listA) {
|
|
699
|
-
return listB =>filter(x => includes(x)(listA))(listB)
|
|
885
|
+
return listB => filter(x => includes(x)(listA))(listB)
|
|
700
886
|
}
|
|
701
887
|
|
|
702
888
|
function intersperse(separator) {
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
889
|
+
return list => {
|
|
890
|
+
let index = -1;
|
|
891
|
+
const len = list.length;
|
|
892
|
+
const willReturn = [];
|
|
707
893
|
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
894
|
+
while (++index < len) {
|
|
895
|
+
if (index === len - 1) {
|
|
896
|
+
willReturn.push(list[index]);
|
|
897
|
+
} else {
|
|
898
|
+
willReturn.push(list[index], separator);
|
|
899
|
+
}
|
|
713
900
|
}
|
|
714
|
-
}
|
|
715
901
|
|
|
716
|
-
|
|
717
|
-
}
|
|
902
|
+
return willReturn
|
|
903
|
+
}
|
|
718
904
|
}
|
|
719
905
|
|
|
720
906
|
function join(glue) {
|
|
721
|
-
return list=> list.join(glue)
|
|
907
|
+
return list => list.join(glue)
|
|
722
908
|
}
|
|
723
909
|
|
|
724
910
|
function last(listOrString) {
|
|
@@ -733,47 +919,51 @@ function lastIndexOf(valueToFind) {
|
|
|
733
919
|
return list => _lastIndexOf(valueToFind, list)
|
|
734
920
|
}
|
|
735
921
|
|
|
736
|
-
function map(fn) {
|
|
737
|
-
return list => {
|
|
738
|
-
let index = 0;
|
|
739
|
-
const willReturn = Array(list.length);
|
|
740
|
-
while (index < list.length) {
|
|
741
|
-
willReturn[index] = fn(list[index], index);
|
|
742
|
-
index++;
|
|
743
|
-
}
|
|
744
|
-
return willReturn
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
|
|
748
922
|
function mapAsync(fn) {
|
|
749
|
-
|
|
750
|
-
|
|
923
|
+
return async list => {
|
|
924
|
+
const willReturn = [];
|
|
751
925
|
let i = 0;
|
|
752
926
|
for (const a of list) {
|
|
753
927
|
willReturn.push(await fn(a, i++));
|
|
754
928
|
}
|
|
755
929
|
|
|
756
930
|
return willReturn
|
|
757
|
-
|
|
931
|
+
}
|
|
758
932
|
}
|
|
759
933
|
|
|
760
|
-
function
|
|
761
|
-
|
|
934
|
+
function mapKeys(fn) {
|
|
935
|
+
return obj => {
|
|
762
936
|
const willReturn = {};
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
937
|
+
|
|
938
|
+
Object.keys(obj).forEach(key => {
|
|
939
|
+
willReturn[fn(key, obj[key])] = obj[key];
|
|
940
|
+
});
|
|
941
|
+
|
|
767
942
|
return willReturn
|
|
768
943
|
}
|
|
769
944
|
}
|
|
770
945
|
|
|
946
|
+
function mapObjectAsync(fn) {
|
|
947
|
+
return async obj => {
|
|
948
|
+
const willReturn = {};
|
|
949
|
+
for (const prop in obj) {
|
|
950
|
+
willReturn[prop] = await fn(obj[prop], prop);
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
return willReturn
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
function mapParallelAsync(fn) {
|
|
958
|
+
return async list => Promise.all(list.map((x, i) => fn(x, i)))
|
|
959
|
+
}
|
|
960
|
+
|
|
771
961
|
function match(pattern) {
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
962
|
+
return input => {
|
|
963
|
+
const willReturn = input.match(pattern);
|
|
964
|
+
|
|
965
|
+
return willReturn === null ? [] : willReturn
|
|
966
|
+
}
|
|
777
967
|
}
|
|
778
968
|
|
|
779
969
|
function maxBy(compareFn, x) {
|
|
@@ -793,66 +983,47 @@ function minBy(compareFn, x) {
|
|
|
793
983
|
return y => (compareFn(y) < compareFn(x) ? y : x)
|
|
794
984
|
}
|
|
795
985
|
|
|
796
|
-
function
|
|
797
|
-
return
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
986
|
+
function modifyItemAtIndex(index, replaceFn) {
|
|
987
|
+
return list => {
|
|
988
|
+
const actualIndex = index < 0 ? list.length + index : index;
|
|
989
|
+
if (index >= list.length || actualIndex < 0) {
|
|
990
|
+
return list
|
|
991
|
+
}
|
|
801
992
|
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
return _obj => path(pathInput, _obj)
|
|
805
|
-
}
|
|
993
|
+
const clone = cloneList$1(list);
|
|
994
|
+
clone[actualIndex] = replaceFn(clone[actualIndex]);
|
|
806
995
|
|
|
807
|
-
|
|
808
|
-
return undefined
|
|
996
|
+
return clone
|
|
809
997
|
}
|
|
810
|
-
|
|
811
|
-
let counter = 0;
|
|
812
|
-
|
|
813
|
-
const pathArrValue = createPath(pathInput);
|
|
998
|
+
}
|
|
814
999
|
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
return undefined
|
|
1000
|
+
function update(index, newValue) {
|
|
1001
|
+
return list => {
|
|
1002
|
+
const clone = cloneList$1(list);
|
|
1003
|
+
if (index === -1) {
|
|
1004
|
+
return clone.fill(newValue, index)
|
|
821
1005
|
}
|
|
822
1006
|
|
|
823
|
-
|
|
824
|
-
counter++;
|
|
1007
|
+
return clone.fill(newValue, index, index + 1)
|
|
825
1008
|
}
|
|
826
|
-
|
|
827
|
-
return willReturn
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
function assoc(prop, newValue) {
|
|
831
|
-
return obj => Object.assign({}, obj, { [prop]: newValue })
|
|
832
1009
|
}
|
|
833
1010
|
|
|
834
|
-
function
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
}
|
|
842
|
-
if (path(path$1)(obj) === undefined) {
|
|
843
|
-
return obj
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
const val = modifyPathFn(Array.prototype.slice.call(path$1, 1), fn, obj[path$1[0]]);
|
|
847
|
-
if (val === obj[path$1[0]]) {
|
|
848
|
-
return obj
|
|
849
|
-
}
|
|
1011
|
+
function modifyFn(property, fn, list) {
|
|
1012
|
+
if (list[property] === undefined) {
|
|
1013
|
+
return list
|
|
1014
|
+
}
|
|
1015
|
+
if (isArray(list)) {
|
|
1016
|
+
return update(property, fn(list[property]))(list)
|
|
1017
|
+
}
|
|
850
1018
|
|
|
851
|
-
|
|
1019
|
+
return {
|
|
1020
|
+
...list,
|
|
1021
|
+
[property]: fn(list[property]),
|
|
1022
|
+
}
|
|
852
1023
|
}
|
|
853
1024
|
|
|
854
|
-
function
|
|
855
|
-
return obj =>
|
|
1025
|
+
function modifyProp(property, fn) {
|
|
1026
|
+
return obj => modifyFn(property, fn, obj)
|
|
856
1027
|
}
|
|
857
1028
|
|
|
858
1029
|
function none(predicate) {
|
|
@@ -871,6 +1042,22 @@ function objOf(key) {
|
|
|
871
1042
|
return value => ({ [key]: value })
|
|
872
1043
|
}
|
|
873
1044
|
|
|
1045
|
+
function objectIncludes(condition) {
|
|
1046
|
+
return obj => {
|
|
1047
|
+
const result = filterObject((conditionValue, conditionProp) =>
|
|
1048
|
+
equals(conditionValue)(obj[conditionProp]),
|
|
1049
|
+
)(condition);
|
|
1050
|
+
|
|
1051
|
+
return Object.keys(result).length === Object.keys(condition).length
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
function createPath(path, delimiter = '.') {
|
|
1056
|
+
return typeof path === 'string'
|
|
1057
|
+
? path.split(delimiter).map(x => (Number.isInteger(Number(x)) ? Number(x) : x))
|
|
1058
|
+
: path
|
|
1059
|
+
}
|
|
1060
|
+
|
|
874
1061
|
function _includes(x, list) {
|
|
875
1062
|
let index = -1;
|
|
876
1063
|
const { length } = list;
|
|
@@ -903,10 +1090,29 @@ function omit(propsToOmit) {
|
|
|
903
1090
|
}
|
|
904
1091
|
}
|
|
905
1092
|
|
|
906
|
-
function
|
|
1093
|
+
function partition(predicate) {
|
|
1094
|
+
return list => {
|
|
1095
|
+
const yes = [];
|
|
1096
|
+
const no = [];
|
|
1097
|
+
let counter = -1;
|
|
1098
|
+
|
|
1099
|
+
while (counter++ < list.length - 1) {
|
|
1100
|
+
if (predicate(list[counter], counter)) {
|
|
1101
|
+
yes.push(list[counter]);
|
|
1102
|
+
} else {
|
|
1103
|
+
no.push(list[counter]);
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
return [yes, no]
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
function partitionObject(predicate) {
|
|
1112
|
+
return obj => {
|
|
907
1113
|
const yes = {};
|
|
908
1114
|
const no = {};
|
|
909
|
-
Object.entries(
|
|
1115
|
+
Object.entries(obj).forEach(([prop, value]) => {
|
|
910
1116
|
if (predicate(value, prop)) {
|
|
911
1117
|
yes[prop] = value;
|
|
912
1118
|
} else {
|
|
@@ -916,31 +1122,75 @@ function partitionObject(predicate, iterable) {
|
|
|
916
1122
|
|
|
917
1123
|
return [yes, no]
|
|
918
1124
|
}
|
|
1125
|
+
}
|
|
919
1126
|
|
|
920
|
-
function
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
1127
|
+
function path(pathInput) {
|
|
1128
|
+
return (obj) => {
|
|
1129
|
+
if (!obj) {
|
|
1130
|
+
return undefined
|
|
1131
|
+
}
|
|
1132
|
+
let willReturn = obj;
|
|
1133
|
+
let counter = 0;
|
|
1134
|
+
|
|
1135
|
+
const pathArrValue = createPath(pathInput);
|
|
1136
|
+
|
|
1137
|
+
while (counter < pathArrValue.length) {
|
|
1138
|
+
if (willReturn === null || willReturn === undefined) {
|
|
1139
|
+
return undefined
|
|
1140
|
+
}
|
|
1141
|
+
if (willReturn[pathArrValue[counter]] === null) {
|
|
1142
|
+
return undefined
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
willReturn = willReturn[pathArrValue[counter]];
|
|
1146
|
+
counter++;
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
return willReturn
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
function pathSatisfies(fn, pathInput) {
|
|
1154
|
+
return obj => Boolean(fn(path(pathInput)(obj)))
|
|
1155
|
+
}
|
|
924
1156
|
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
1157
|
+
/**
|
|
1158
|
+
* Source:
|
|
1159
|
+
* https://github.com/denoland/std/blob/main/collections/permutations.ts
|
|
1160
|
+
*/
|
|
1161
|
+
function permutations(inputArray) {
|
|
1162
|
+
const result = [];
|
|
1163
|
+
const array = cloneList$1(inputArray);
|
|
1164
|
+
const k = array.length;
|
|
1165
|
+
if (k === 0) {
|
|
1166
|
+
return result;
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
const c = new Array(k).fill(0);
|
|
1170
|
+
|
|
1171
|
+
result.push([...array]);
|
|
1172
|
+
|
|
1173
|
+
let i = 1;
|
|
1174
|
+
|
|
1175
|
+
while (i < k) {
|
|
1176
|
+
if (c[i] < i) {
|
|
1177
|
+
if (i % 2 === 0) {
|
|
1178
|
+
[array[0], array[i]] = [array[i], array[0]];
|
|
1179
|
+
} else {
|
|
1180
|
+
[array[c[i]], array[i]] = [array[i], array[c[i]]];
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
result.push([...array]);
|
|
1184
|
+
|
|
1185
|
+
c[i] += 1;
|
|
1186
|
+
i = 1;
|
|
928
1187
|
} else {
|
|
929
|
-
|
|
1188
|
+
c[i] = 0;
|
|
1189
|
+
i += 1;
|
|
930
1190
|
}
|
|
931
1191
|
}
|
|
932
1192
|
|
|
933
|
-
return
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
function partition(predicate) {
|
|
937
|
-
return iterable => {
|
|
938
|
-
if (!isArray(iterable)) {
|
|
939
|
-
return partitionObject(predicate, iterable)
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
return partitionArray(predicate, iterable)
|
|
943
|
-
}
|
|
1193
|
+
return result;
|
|
944
1194
|
}
|
|
945
1195
|
|
|
946
1196
|
function pick(propsToPick) {
|
|
@@ -1063,30 +1313,35 @@ function pipe(...inputs) {
|
|
|
1063
1313
|
}
|
|
1064
1314
|
|
|
1065
1315
|
async function pipeAsync(input, ...fnList) {
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1316
|
+
let willReturn = input;
|
|
1317
|
+
for (const fn of fnList) {
|
|
1318
|
+
const initialResult = fn(willReturn);
|
|
1319
|
+
willReturn =
|
|
1320
|
+
type(initialResult) === 'Promise' ? await initialResult : initialResult;
|
|
1321
|
+
}
|
|
1322
|
+
return willReturn
|
|
1072
1323
|
}
|
|
1073
1324
|
|
|
1074
1325
|
function pluck(property) {
|
|
1075
|
-
|
|
1076
|
-
|
|
1326
|
+
return list => {
|
|
1327
|
+
const willReturn = [];
|
|
1077
1328
|
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1329
|
+
list.forEach(x => {
|
|
1330
|
+
if (x[property] !== undefined) {
|
|
1331
|
+
willReturn.push(x[property]);
|
|
1332
|
+
}
|
|
1333
|
+
});
|
|
1083
1334
|
|
|
1084
|
-
|
|
1085
|
-
}
|
|
1335
|
+
return willReturn
|
|
1336
|
+
}
|
|
1086
1337
|
}
|
|
1087
1338
|
|
|
1088
1339
|
function prepend(x) {
|
|
1089
|
-
return list=> [x].concat(list)
|
|
1340
|
+
return list => [x].concat(list)
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
function prop(searchProperty) {
|
|
1344
|
+
return obj => (obj ? obj[searchProperty] : undefined)
|
|
1090
1345
|
}
|
|
1091
1346
|
|
|
1092
1347
|
function propEq(valueToMatch, propToFind) {
|
|
@@ -1105,72 +1360,119 @@ function propOr(defaultValue, property) {
|
|
|
1105
1360
|
return defaultValue
|
|
1106
1361
|
}
|
|
1107
1362
|
|
|
1108
|
-
return defaultTo(defaultValue
|
|
1363
|
+
return defaultTo(defaultValue)(obj[property])
|
|
1109
1364
|
}
|
|
1110
1365
|
}
|
|
1111
1366
|
|
|
1112
1367
|
function propSatisfies(predicate, property) {
|
|
1113
|
-
return obj => predicate(
|
|
1368
|
+
return obj => predicate(obj[property])
|
|
1114
1369
|
}
|
|
1115
1370
|
|
|
1116
|
-
function
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1371
|
+
function rangeDescending(start, end) {
|
|
1372
|
+
const len = start - end;
|
|
1373
|
+
const willReturn = Array(len);
|
|
1374
|
+
|
|
1375
|
+
for (let i = 0; i < len; i++) {
|
|
1376
|
+
willReturn[i] = start - i;
|
|
1377
|
+
}
|
|
1121
1378
|
|
|
1122
|
-
|
|
1379
|
+
return willReturn
|
|
1380
|
+
}
|
|
1123
1381
|
|
|
1124
|
-
|
|
1125
|
-
|
|
1382
|
+
function range(start) {
|
|
1383
|
+
return end => {
|
|
1384
|
+
if (Number.isNaN(Number(start)) || Number.isNaN(Number(end))) {
|
|
1385
|
+
throw new TypeError('Both arguments to range must be numbers')
|
|
1386
|
+
}
|
|
1126
1387
|
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1388
|
+
if (end === start) {
|
|
1389
|
+
return []
|
|
1390
|
+
}
|
|
1391
|
+
if (end < start) return rangeDescending(start,end)
|
|
1130
1392
|
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
}
|
|
1393
|
+
const len = end - start;
|
|
1394
|
+
const willReturn = Array(len);
|
|
1134
1395
|
|
|
1135
|
-
|
|
1136
|
-
|
|
1396
|
+
for (let i = 0; i < len; i++) {
|
|
1397
|
+
willReturn[i] = start + i;
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
return willReturn
|
|
1401
|
+
}
|
|
1137
1402
|
}
|
|
1138
1403
|
|
|
1139
1404
|
function replace(pattern, replacer) {
|
|
1140
1405
|
return str => str.replace(pattern, replacer)
|
|
1141
1406
|
}
|
|
1142
1407
|
|
|
1143
|
-
function
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1408
|
+
function shuffle(listInput) {
|
|
1409
|
+
const list = cloneList(listInput);
|
|
1410
|
+
let counter = list.length;
|
|
1411
|
+
while (counter > 0) {
|
|
1412
|
+
const index = Math.floor(Math.random() * counter);
|
|
1413
|
+
counter--;
|
|
1414
|
+
const temp = list[counter];
|
|
1415
|
+
list[counter] = list[index];
|
|
1416
|
+
list[index] = temp;
|
|
1417
|
+
}
|
|
1149
1418
|
|
|
1150
|
-
|
|
1151
|
-
|
|
1419
|
+
return list
|
|
1420
|
+
}
|
|
1152
1421
|
|
|
1153
|
-
|
|
1154
|
-
|
|
1422
|
+
function sort(sortFn) {
|
|
1423
|
+
return list => cloneList$1(list).sort(sortFn)
|
|
1155
1424
|
}
|
|
1156
1425
|
|
|
1157
|
-
function
|
|
1158
|
-
|
|
1426
|
+
function sortByFn (
|
|
1427
|
+
sortFn,
|
|
1428
|
+
list,
|
|
1429
|
+
descending
|
|
1430
|
+
){
|
|
1431
|
+
const clone = cloneList$1(list);
|
|
1432
|
+
|
|
1433
|
+
return clone.sort((a, b) => {
|
|
1434
|
+
const aSortResult = sortFn(a);
|
|
1435
|
+
const bSortResult = sortFn(b);
|
|
1436
|
+
|
|
1437
|
+
if (aSortResult === bSortResult) {
|
|
1438
|
+
return 0
|
|
1439
|
+
}
|
|
1440
|
+
if(
|
|
1441
|
+
descending
|
|
1442
|
+
) return aSortResult > bSortResult ? -1 : 1
|
|
1443
|
+
|
|
1444
|
+
return aSortResult < bSortResult ? -1 : 1
|
|
1445
|
+
})
|
|
1159
1446
|
}
|
|
1160
1447
|
|
|
1161
|
-
function sortBy(sortFn){
|
|
1162
|
-
|
|
1163
|
-
|
|
1448
|
+
function sortBy(sortFn) {
|
|
1449
|
+
return list => sortByFn(sortFn, list, false)
|
|
1450
|
+
}
|
|
1164
1451
|
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1452
|
+
function sortByDescending(sortFn) {
|
|
1453
|
+
return list => sortByFn(sortFn, list, true)
|
|
1454
|
+
}
|
|
1168
1455
|
|
|
1169
|
-
|
|
1456
|
+
function sortByPath(sortPath) {
|
|
1457
|
+
return list => sortBy(path(sortPath))(list)
|
|
1458
|
+
}
|
|
1170
1459
|
|
|
1171
|
-
|
|
1172
|
-
|
|
1460
|
+
function sortByPathDescending(sortPath) {
|
|
1461
|
+
return list => sortByDescending(path(sortPath))(list)
|
|
1173
1462
|
}
|
|
1463
|
+
|
|
1464
|
+
function sortObject(predicate) {
|
|
1465
|
+
return obj => {
|
|
1466
|
+
const keys = Object.keys(obj);
|
|
1467
|
+
const sortedKeys = sort((a, b) => predicate(a, b, obj[a], obj[b]))(keys);
|
|
1468
|
+
|
|
1469
|
+
const toReturn = {};
|
|
1470
|
+
sortedKeys.forEach(singleKey => {
|
|
1471
|
+
toReturn[singleKey] = obj[singleKey];
|
|
1472
|
+
});
|
|
1473
|
+
|
|
1474
|
+
return toReturn
|
|
1475
|
+
}
|
|
1174
1476
|
}
|
|
1175
1477
|
|
|
1176
1478
|
function sortHelper(a, b, listOfSortingFns) {
|
|
@@ -1185,37 +1487,37 @@ function sortHelper(a, b, listOfSortingFns) {
|
|
|
1185
1487
|
}
|
|
1186
1488
|
|
|
1187
1489
|
function sortWith(listOfSortingFns) {
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1490
|
+
return list => {
|
|
1491
|
+
if (Array.isArray(list) === false) {
|
|
1492
|
+
return []
|
|
1493
|
+
}
|
|
1192
1494
|
|
|
1193
|
-
|
|
1194
|
-
|
|
1495
|
+
const clone = list.slice();
|
|
1496
|
+
clone.sort((a, b) => sortHelper(a, b, listOfSortingFns));
|
|
1195
1497
|
|
|
1196
|
-
|
|
1197
|
-
}
|
|
1498
|
+
return clone
|
|
1499
|
+
}
|
|
1198
1500
|
}
|
|
1199
1501
|
|
|
1200
|
-
function split(separator){
|
|
1201
|
-
|
|
1502
|
+
function split(separator) {
|
|
1503
|
+
return str => str.split(separator)
|
|
1202
1504
|
}
|
|
1203
1505
|
|
|
1204
1506
|
function splitEvery(sliceLength) {
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1507
|
+
return list => {
|
|
1508
|
+
if (sliceLength < 1) {
|
|
1509
|
+
throw new Error('First argument to splitEvery must be a positive integer')
|
|
1510
|
+
}
|
|
1209
1511
|
|
|
1210
|
-
|
|
1211
|
-
|
|
1512
|
+
const willReturn = [];
|
|
1513
|
+
let counter = 0;
|
|
1212
1514
|
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1515
|
+
while (counter < list.length) {
|
|
1516
|
+
willReturn.push(list.slice(counter, (counter += sliceLength)));
|
|
1517
|
+
}
|
|
1216
1518
|
|
|
1217
|
-
|
|
1218
|
-
}
|
|
1519
|
+
return willReturn
|
|
1520
|
+
}
|
|
1219
1521
|
}
|
|
1220
1522
|
|
|
1221
1523
|
function symmetricDifference(x) {
|
|
@@ -1261,24 +1563,24 @@ function takeLast(numberOfItems) {
|
|
|
1261
1563
|
}
|
|
1262
1564
|
|
|
1263
1565
|
function takeLastWhile(predicate) {
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1566
|
+
return input => {
|
|
1567
|
+
if (input.length === 0) {
|
|
1568
|
+
return input
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
const toReturn = [];
|
|
1572
|
+
let counter = input.length;
|
|
1573
|
+
|
|
1574
|
+
while (counter) {
|
|
1575
|
+
const item = input[--counter];
|
|
1576
|
+
if (!predicate(item)) {
|
|
1577
|
+
break
|
|
1578
|
+
}
|
|
1579
|
+
toReturn.push(item);
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
return toReturn.reverse()
|
|
1583
|
+
}
|
|
1282
1584
|
}
|
|
1283
1585
|
|
|
1284
1586
|
function takeWhile(predicate) {
|
|
@@ -1298,15 +1600,15 @@ function takeWhile(predicate) {
|
|
|
1298
1600
|
}
|
|
1299
1601
|
|
|
1300
1602
|
function tap(fn) {
|
|
1301
|
-
|
|
1302
|
-
|
|
1603
|
+
return x => {
|
|
1604
|
+
fn(x);
|
|
1303
1605
|
|
|
1304
|
-
|
|
1305
|
-
}
|
|
1606
|
+
return x
|
|
1607
|
+
}
|
|
1306
1608
|
}
|
|
1307
1609
|
|
|
1308
1610
|
function test(pattern) {
|
|
1309
|
-
|
|
1611
|
+
return str => str.search(pattern) !== -1
|
|
1310
1612
|
}
|
|
1311
1613
|
|
|
1312
1614
|
function tryCatch(fn, fallback) {
|
|
@@ -1321,7 +1623,7 @@ function tryCatch(fn, fallback) {
|
|
|
1321
1623
|
|
|
1322
1624
|
function union(x) {
|
|
1323
1625
|
return y => {
|
|
1324
|
-
const toReturn = cloneList(x);
|
|
1626
|
+
const toReturn = cloneList$1(x);
|
|
1325
1627
|
|
|
1326
1628
|
y.forEach(yInstance => {
|
|
1327
1629
|
if (!includes(yInstance)(x)) {
|
|
@@ -1385,11 +1687,11 @@ function uniq(list) {
|
|
|
1385
1687
|
}
|
|
1386
1688
|
|
|
1387
1689
|
function uniqBy(fn) {
|
|
1388
|
-
|
|
1389
|
-
|
|
1690
|
+
return list => {
|
|
1691
|
+
const set = new _Set();
|
|
1390
1692
|
|
|
1391
|
-
|
|
1392
|
-
|
|
1693
|
+
return list.filter(item => set.checkUniqueness(fn(item)))
|
|
1694
|
+
}
|
|
1393
1695
|
}
|
|
1394
1696
|
|
|
1395
1697
|
function includesWith(predicate, target, list) {
|
|
@@ -1408,20 +1710,20 @@ function includesWith(predicate, target, list) {
|
|
|
1408
1710
|
}
|
|
1409
1711
|
|
|
1410
1712
|
function uniqWith(predicate) {
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1713
|
+
return list => {
|
|
1714
|
+
let index = -1;
|
|
1715
|
+
const willReturn = [];
|
|
1414
1716
|
|
|
1415
|
-
|
|
1416
|
-
|
|
1717
|
+
while (++index < list.length) {
|
|
1718
|
+
const value = list[index];
|
|
1417
1719
|
|
|
1418
|
-
|
|
1419
|
-
|
|
1720
|
+
if (!includesWith(predicate, value, willReturn)) {
|
|
1721
|
+
willReturn.push(value);
|
|
1722
|
+
}
|
|
1420
1723
|
}
|
|
1421
|
-
}
|
|
1422
1724
|
|
|
1423
|
-
|
|
1424
|
-
}
|
|
1725
|
+
return willReturn
|
|
1726
|
+
}
|
|
1425
1727
|
}
|
|
1426
1728
|
|
|
1427
1729
|
function unless(predicate, whenFalseFn) {
|
|
@@ -1443,17 +1745,6 @@ function unwind(property) {
|
|
|
1443
1745
|
}
|
|
1444
1746
|
}
|
|
1445
1747
|
|
|
1446
|
-
function update(index, newValue) {
|
|
1447
|
-
return list => {
|
|
1448
|
-
const clone = cloneList(list);
|
|
1449
|
-
if (index === -1) {
|
|
1450
|
-
return clone.fill(newValue, index)
|
|
1451
|
-
}
|
|
1452
|
-
|
|
1453
|
-
return clone.fill(newValue, index, index + 1)
|
|
1454
|
-
}
|
|
1455
|
-
}
|
|
1456
|
-
|
|
1457
1748
|
function when(predicate, whenTrueFn) {
|
|
1458
1749
|
return input => {
|
|
1459
1750
|
if (!predicate(input)) {
|
|
@@ -1484,4 +1775,128 @@ function zipWith(fn, x) {
|
|
|
1484
1775
|
)
|
|
1485
1776
|
}
|
|
1486
1777
|
|
|
1487
|
-
|
|
1778
|
+
exports._arity = _arity;
|
|
1779
|
+
exports._includes = _includes;
|
|
1780
|
+
exports._indexOf = _indexOf;
|
|
1781
|
+
exports._lastIndexOf = _lastIndexOf;
|
|
1782
|
+
exports.addProp = addProp;
|
|
1783
|
+
exports.addPropToObjects = addPropToObjects;
|
|
1784
|
+
exports.all = all;
|
|
1785
|
+
exports.allPass = allPass;
|
|
1786
|
+
exports.any = any;
|
|
1787
|
+
exports.anyPass = anyPass;
|
|
1788
|
+
exports.append = append;
|
|
1789
|
+
exports.ascend = ascend;
|
|
1790
|
+
exports.checkObjectWithSpec = checkObjectWithSpec;
|
|
1791
|
+
exports.compact = compact;
|
|
1792
|
+
exports.complement = complement;
|
|
1793
|
+
exports.concat = concat;
|
|
1794
|
+
exports.count = count;
|
|
1795
|
+
exports.countBy = countBy;
|
|
1796
|
+
exports.createCompareFunction = createCompareFunction;
|
|
1797
|
+
exports.createObjectFromKeys = createObjectFromKeys;
|
|
1798
|
+
exports.defaultTo = defaultTo;
|
|
1799
|
+
exports.descend = descend;
|
|
1800
|
+
exports.drop = drop;
|
|
1801
|
+
exports.dropLast = dropLast;
|
|
1802
|
+
exports.dropLastWhile = dropLastWhile;
|
|
1803
|
+
exports.dropWhile = dropWhile;
|
|
1804
|
+
exports.eqBy = eqBy;
|
|
1805
|
+
exports.eqProps = eqProps;
|
|
1806
|
+
exports.equals = equals;
|
|
1807
|
+
exports.equalsFn = equalsFn;
|
|
1808
|
+
exports.evolve = evolve;
|
|
1809
|
+
exports.excludes = excludes;
|
|
1810
|
+
exports.filter = filter;
|
|
1811
|
+
exports.filterObject = filterObject;
|
|
1812
|
+
exports.find = find;
|
|
1813
|
+
exports.findIndex = findIndex;
|
|
1814
|
+
exports.findLast = findLast;
|
|
1815
|
+
exports.findLastIndex = findLastIndex;
|
|
1816
|
+
exports.findNth = findNth;
|
|
1817
|
+
exports.flatMap = flatMap;
|
|
1818
|
+
exports.flatten = flatten;
|
|
1819
|
+
exports.flattenObject = flattenObject;
|
|
1820
|
+
exports.flattenObjectHelper = flattenObjectHelper;
|
|
1821
|
+
exports.groupBy = groupBy;
|
|
1822
|
+
exports.groupByFallback = groupByFallback;
|
|
1823
|
+
exports.head = head;
|
|
1824
|
+
exports.includes = includes;
|
|
1825
|
+
exports.indexOf = indexOf;
|
|
1826
|
+
exports.init = init;
|
|
1827
|
+
exports.innerJoin = innerJoin;
|
|
1828
|
+
exports.interpolate = interpolate;
|
|
1829
|
+
exports.intersection = intersection;
|
|
1830
|
+
exports.intersperse = intersperse;
|
|
1831
|
+
exports.join = join;
|
|
1832
|
+
exports.last = last;
|
|
1833
|
+
exports.lastIndexOf = lastIndexOf;
|
|
1834
|
+
exports.map = map;
|
|
1835
|
+
exports.mapAsync = mapAsync;
|
|
1836
|
+
exports.mapFn = mapFn;
|
|
1837
|
+
exports.mapKeys = mapKeys;
|
|
1838
|
+
exports.mapObject = mapObject;
|
|
1839
|
+
exports.mapObjectAsync = mapObjectAsync;
|
|
1840
|
+
exports.mapParallelAsync = mapParallelAsync;
|
|
1841
|
+
exports.match = match;
|
|
1842
|
+
exports.maxBy = maxBy;
|
|
1843
|
+
exports.merge = merge;
|
|
1844
|
+
exports.mergeTypes = mergeTypes;
|
|
1845
|
+
exports.minBy = minBy;
|
|
1846
|
+
exports.modifyItemAtIndex = modifyItemAtIndex;
|
|
1847
|
+
exports.modifyProp = modifyProp;
|
|
1848
|
+
exports.none = none;
|
|
1849
|
+
exports.objOf = objOf;
|
|
1850
|
+
exports.objectIncludes = objectIncludes;
|
|
1851
|
+
exports.omit = omit;
|
|
1852
|
+
exports.partition = partition;
|
|
1853
|
+
exports.partitionObject = partitionObject;
|
|
1854
|
+
exports.path = path;
|
|
1855
|
+
exports.pathSatisfies = pathSatisfies;
|
|
1856
|
+
exports.permutations = permutations;
|
|
1857
|
+
exports.pick = pick;
|
|
1858
|
+
exports.pipe = pipe;
|
|
1859
|
+
exports.pipeAsync = pipeAsync;
|
|
1860
|
+
exports.pluck = pluck;
|
|
1861
|
+
exports.prepend = prepend;
|
|
1862
|
+
exports.prop = prop;
|
|
1863
|
+
exports.propEq = propEq;
|
|
1864
|
+
exports.propOr = propOr;
|
|
1865
|
+
exports.propSatisfies = propSatisfies;
|
|
1866
|
+
exports.range = range;
|
|
1867
|
+
exports.reduce = reduce;
|
|
1868
|
+
exports.reject = reject;
|
|
1869
|
+
exports.rejectObject = rejectObject;
|
|
1870
|
+
exports.replace = replace;
|
|
1871
|
+
exports.shuffle = shuffle;
|
|
1872
|
+
exports.sort = sort;
|
|
1873
|
+
exports.sortBy = sortBy;
|
|
1874
|
+
exports.sortByDescending = sortByDescending;
|
|
1875
|
+
exports.sortByFn = sortByFn;
|
|
1876
|
+
exports.sortByPath = sortByPath;
|
|
1877
|
+
exports.sortByPathDescending = sortByPathDescending;
|
|
1878
|
+
exports.sortObject = sortObject;
|
|
1879
|
+
exports.sortWith = sortWith;
|
|
1880
|
+
exports.split = split;
|
|
1881
|
+
exports.splitEvery = splitEvery;
|
|
1882
|
+
exports.symmetricDifference = symmetricDifference;
|
|
1883
|
+
exports.tail = tail;
|
|
1884
|
+
exports.take = take;
|
|
1885
|
+
exports.takeLast = takeLast;
|
|
1886
|
+
exports.takeLastWhile = takeLastWhile;
|
|
1887
|
+
exports.takeWhile = takeWhile;
|
|
1888
|
+
exports.tap = tap;
|
|
1889
|
+
exports.test = test;
|
|
1890
|
+
exports.transformFlatObject = transformFlatObject;
|
|
1891
|
+
exports.tryCatch = tryCatch;
|
|
1892
|
+
exports.type = type;
|
|
1893
|
+
exports.union = union;
|
|
1894
|
+
exports.uniq = uniq;
|
|
1895
|
+
exports.uniqBy = uniqBy;
|
|
1896
|
+
exports.uniqWith = uniqWith;
|
|
1897
|
+
exports.unless = unless;
|
|
1898
|
+
exports.unwind = unwind;
|
|
1899
|
+
exports.update = update;
|
|
1900
|
+
exports.when = when;
|
|
1901
|
+
exports.zip = zip;
|
|
1902
|
+
exports.zipWith = zipWith;
|