rambda 10.0.0-alpha.0 → 10.0.0-beta.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.
Files changed (64) hide show
  1. package/CHANGELOG.md +124 -16
  2. package/README.md +5526 -1730
  3. package/dist/{rambda.esm.js → rambda.cjs} +663 -355
  4. package/dist/rambda.js +545 -456
  5. package/dist/rambda.umd.js +563 -357
  6. package/immutable.d.ts +321 -343
  7. package/index.d.ts +321 -343
  8. package/package.json +20 -13
  9. package/rambda.js +16 -1
  10. package/src/addProp.js +3 -0
  11. package/src/append.js +5 -5
  12. package/src/ascend.js +16 -0
  13. package/src/compact.js +12 -0
  14. package/src/concat.js +1 -1
  15. package/src/count.js +7 -7
  16. package/src/countBy.js +12 -12
  17. package/src/createObjectFromKeys.js +10 -0
  18. package/src/descend.js +10 -0
  19. package/src/dropLast.js +1 -3
  20. package/src/eqProps.js +1 -2
  21. package/src/equals.js +2 -2
  22. package/src/evolve.js +2 -23
  23. package/src/filter.js +14 -14
  24. package/src/find.js +10 -10
  25. package/src/findIndex.js +9 -9
  26. package/src/findLast.js +8 -8
  27. package/src/findLastIndex.js +8 -8
  28. package/src/findNth.js +16 -0
  29. package/src/groupBy.js +14 -13
  30. package/src/includes.js +12 -13
  31. package/src/interpolate.js +29 -0
  32. package/src/intersection.js +1 -1
  33. package/src/intersperse.js +12 -12
  34. package/src/join.js +1 -1
  35. package/src/mapAsync.js +3 -3
  36. package/src/mapKeys.js +11 -0
  37. package/src/mapObjectAsync.js +9 -9
  38. package/src/mapParallelAsync.js +3 -0
  39. package/src/match.js +5 -5
  40. package/src/modifyProp.js +20 -0
  41. package/src/objectIncludes.js +12 -0
  42. package/src/partition.js +13 -37
  43. package/src/partitionObject.js +15 -0
  44. package/src/permutations.js +40 -0
  45. package/src/pipeAsync.js +7 -6
  46. package/src/pluck.js +9 -9
  47. package/src/prepend.js +1 -1
  48. package/src/propSatisfies.js +1 -3
  49. package/src/range.js +35 -12
  50. package/src/reject.js +1 -1
  51. package/src/rejectObject.js +13 -0
  52. package/src/shuffle.js +13 -0
  53. package/src/sort.js +1 -1
  54. package/src/sortBy.js +12 -10
  55. package/src/sortObject.js +15 -0
  56. package/src/sortWith.js +8 -8
  57. package/src/split.js +2 -2
  58. package/src/splitEvery.js +11 -11
  59. package/src/takeLastWhile.js +18 -18
  60. package/src/tap.js +4 -4
  61. package/src/test.js +1 -1
  62. package/src/uniqBy.js +4 -4
  63. package/src/uniqWith.js +10 -10
  64. package/src/modifyPath.js +0 -30
@@ -1,3 +1,9 @@
1
+ 'use strict';
2
+
3
+ function addProp(key, value) {
4
+ return obj => ({ ...obj, [key]: value })
5
+ }
6
+
1
7
  function all(predicate) {
2
8
  return list => {
3
9
  for (let i = 0; i < list.length; i++) {
@@ -52,15 +58,32 @@ function anyPass(predicates) {
52
58
  }
53
59
  }
54
60
 
55
- const cloneList = list => Array.prototype.slice.call(list);
61
+ const cloneList$1 = list => Array.prototype.slice.call(list);
56
62
 
57
63
  function append(x) {
58
- return list=> {
59
- const clone = cloneList(list);
60
- clone.push(x);
64
+ return list => {
65
+ const clone = cloneList$1(list);
66
+ clone.push(x);
61
67
 
62
- return clone
63
- }
68
+ return clone
69
+ }
70
+ }
71
+
72
+ function createCompareFunction(a, b, winner, loser) {
73
+ if (a === b) {
74
+ return 0
75
+ }
76
+
77
+ return a < b ? winner : loser
78
+ }
79
+
80
+ function ascend(getFunction) {
81
+ return (a, b) => {
82
+ const aValue = getFunction(a);
83
+ const bValue = getFunction(b);
84
+
85
+ return createCompareFunction(aValue, bValue, -1, 1)
86
+ }
64
87
  }
65
88
 
66
89
  function checkObjectWithSpec(conditions) {
@@ -80,41 +103,100 @@ function checkObjectWithSpec(conditions) {
80
103
  }
81
104
  }
82
105
 
106
+ const { isArray } = Array;
107
+
108
+ function filter(predicate) {
109
+ return list => {
110
+ if (!list) {
111
+ throw new Error('Incorrect iterable input')
112
+ }
113
+ let index = 0;
114
+ const len = list.length;
115
+ const willReturn = [];
116
+
117
+ while (index < len) {
118
+ if (predicate(list[index], index)) {
119
+ willReturn.push(list[index]);
120
+ }
121
+
122
+ index++;
123
+ }
124
+
125
+ return willReturn
126
+ }
127
+ }
128
+
129
+ function reject(predicate) {
130
+ return list => filter(x => !predicate(x))(list)
131
+ }
132
+
133
+ function rejectObject(predicate) {
134
+ return obj => {
135
+ const willReturn = {};
136
+
137
+ for (const prop in obj) {
138
+ if (!predicate(obj[prop], prop, obj)) {
139
+ willReturn[prop] = obj[prop];
140
+ }
141
+ }
142
+
143
+ return willReturn
144
+ }
145
+ }
146
+
147
+ const isNullOrUndefined = x => x === null || x === undefined;
148
+
149
+ function compact(input){
150
+ if(isArray(input)){
151
+ return reject(isNullOrUndefined)(input)
152
+ }
153
+ return rejectObject(isNullOrUndefined)(input)
154
+ }
155
+
83
156
  function complement(fn) {
84
157
  return (...input) => !fn(...input)
85
158
  }
86
159
 
87
160
  function concat(x) {
88
- return y => typeof x === 'string' ? `${x}${y}` : [...x, ...y]
161
+ return y => (typeof x === 'string' ? `${x}${y}` : [...x, ...y])
89
162
  }
90
163
 
91
- const { isArray } = Array;
164
+ function count(predicate) {
165
+ return list => {
166
+ if (!isArray(list)) {
167
+ return 0
168
+ }
92
169
 
93
- function count(predicate, ) {
94
- return list => {
95
- if (!isArray(list)) {
96
- return 0
170
+ return list.filter(x => predicate(x)).length
97
171
  }
98
-
99
- return list.filter(x => predicate(x)).length
100
- }
101
172
  }
102
173
 
103
174
  function countBy(fn) {
104
- return list => {
105
- const willReturn = {};
175
+ return list => {
176
+ const willReturn = {};
106
177
 
107
- list.forEach(item => {
108
- const key = fn(item);
109
- if (!willReturn[key]) {
110
- willReturn[key] = 1;
111
- } else {
112
- willReturn[key]++;
113
- }
114
- });
178
+ list.forEach(item => {
179
+ const key = fn(item);
180
+ if (!willReturn[key]) {
181
+ willReturn[key] = 1;
182
+ } else {
183
+ willReturn[key]++;
184
+ }
185
+ });
115
186
 
116
- return willReturn
187
+ return willReturn
188
+ }
117
189
  }
190
+
191
+ function createObjectFromKeys(keys) {
192
+ return fn => {
193
+ const result = {};
194
+ keys.forEach((key, index) => {
195
+ result[key] = fn(key, index);
196
+ });
197
+
198
+ return result
199
+ }
118
200
  }
119
201
 
120
202
  function isFalsy(input) {
@@ -129,6 +211,15 @@ function defaultTo(defaultArgument, input) {
129
211
  return isFalsy(input) ? defaultArgument : input
130
212
  }
131
213
 
214
+ function descend(getFunction) {
215
+ return (a, b) => {
216
+ const aValue = getFunction(a);
217
+ const bValue = getFunction(b);
218
+
219
+ return createCompareFunction(aValue, bValue, 1, -1)
220
+ }
221
+ }
222
+
132
223
  function drop(howManyToDrop, listOrString) {
133
224
  if (arguments.length === 1) {
134
225
  return _list => drop(howManyToDrop, _list)
@@ -138,9 +229,7 @@ function drop(howManyToDrop, listOrString) {
138
229
  }
139
230
 
140
231
  function dropLast(numberItems) {
141
- return list => numberItems > 0
142
- ? list.slice(0, -numberItems)
143
- : list.slice()
232
+ return list => (numberItems > 0 ? list.slice(0, -numberItems) : list.slice())
144
233
  }
145
234
 
146
235
  function dropLastWhile(predicate) {
@@ -300,7 +389,7 @@ function parseRegex(maybeRegex) {
300
389
  }
301
390
 
302
391
  function equalsFn(a, b) {
303
- if (Object.is(a, b)) {
392
+ if (Object.is(a, b)) {
304
393
  return true
305
394
  }
306
395
 
@@ -409,19 +498,15 @@ function equalsFn(a, b) {
409
498
  return false
410
499
  }
411
500
  function equals(a) {
412
- return b => equalsFn(a, b)
501
+ return b => equalsFn(a, b)
413
502
  }
414
503
 
415
504
  function eqBy(fn, a) {
416
505
  return b => equalsFn(fn(a), fn(b))
417
506
  }
418
507
 
419
- function prop(searchProperty) {
420
- return obj => (obj ? obj[searchProperty] : undefined)
421
- }
422
-
423
508
  function eqProps(property, objA) {
424
- return objB => equalsFn(prop(property)(objA), prop(property)(objB))
509
+ return objB => equalsFn( objA[property], objB[property] )
425
510
  }
426
511
 
427
512
  const { keys } = Object;
@@ -443,73 +528,30 @@ function mapObject(fn) {
443
528
  }
444
529
  }
445
530
 
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
531
  function evolve(rules) {
468
- return obj => evolveFn(rules, obj)
469
- }
532
+ return mapObject((x, prop) => type(rules[prop]) === 'Function' ? rules[prop](x): x)
533
+ }
470
534
 
471
535
  function includes(valueToFind) {
472
- return iterable =>
473
- {
474
- if (typeof iterable === 'string') {
475
- return iterable.includes(valueToFind)
476
- }
477
- if (!iterable) {
478
- throw new TypeError(`Cannot read property \'indexOf\' of ${iterable}`)
479
- }
480
- if (!isArray(iterable)) {
481
- return false
482
- }
536
+ return iterable => {
537
+ if (typeof iterable === 'string') {
538
+ return iterable.includes(valueToFind)
539
+ }
540
+ if (!iterable) {
541
+ throw new TypeError(`Cannot read property \'indexOf\' of ${iterable}`)
542
+ }
543
+ if (!isArray(iterable)) {
544
+ return false
545
+ }
483
546
 
484
- return _indexOf(valueToFind, iterable) > -1
485
- }
547
+ return _indexOf(valueToFind, iterable) > -1
548
+ }
486
549
  }
487
550
 
488
551
  function excludes(valueToFind) {
489
552
  return iterable => !includes(valueToFind)(iterable)
490
553
  }
491
554
 
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
555
  function filterObject(predicate) {
514
556
  return obj => {
515
557
  const willReturn = {};
@@ -525,62 +567,79 @@ function filterObject(predicate) {
525
567
  }
526
568
 
527
569
  function find(predicate) {
528
- return list => {
529
- let index = 0;
530
- const len = list.length;
570
+ return list => {
571
+ let index = 0;
572
+ const len = list.length;
531
573
 
532
- while (index < len) {
533
- const x = list[index];
534
- if (predicate(x)) {
535
- return x
536
- }
574
+ while (index < len) {
575
+ const x = list[index];
576
+ if (predicate(x)) {
577
+ return x
578
+ }
537
579
 
538
- index++;
580
+ index++;
581
+ }
539
582
  }
540
583
  }
541
- }
542
584
 
543
585
  function findIndex(predicate) {
544
- return list => {
545
- const len = list.length;
546
- let index = -1;
586
+ return list => {
587
+ const len = list.length;
588
+ let index = -1;
547
589
 
548
- while (++index < len) {
549
- if (predicate(list[index])) {
550
- return index
590
+ while (++index < len) {
591
+ if (predicate(list[index])) {
592
+ return index
593
+ }
551
594
  }
552
- }
553
595
 
554
- return -1
555
- }
596
+ return -1
597
+ }
556
598
  }
557
599
 
558
600
  function findLast(predicate) {
559
- return list => {
560
- let index = list.length;
601
+ return list => {
602
+ let index = list.length;
561
603
 
562
- while (--index >= 0) {
563
- if (predicate(list[index])) {
564
- return list[index]
604
+ while (--index >= 0) {
605
+ if (predicate(list[index])) {
606
+ return list[index]
607
+ }
565
608
  }
566
- }
567
609
 
568
- return undefined
569
- }
610
+ return undefined
611
+ }
570
612
  }
571
613
 
572
614
  function findLastIndex(fn) {
573
- return list => {
574
- let index = list.length;
615
+ return list => {
616
+ let index = list.length;
575
617
 
576
- while (--index >= 0) {
577
- if (fn(list[index])) {
578
- return index
618
+ while (--index >= 0) {
619
+ if (fn(list[index])) {
620
+ return index
621
+ }
579
622
  }
580
- }
581
623
 
582
- return -1
624
+ return -1
625
+ }
583
626
  }
627
+
628
+ function findNth(predicate, nth) {
629
+ return list => {
630
+ let index = 0;
631
+ const len = list.length;
632
+
633
+ while (index < len) {
634
+ const x = list[index];
635
+ if (predicate(x)) {
636
+ if (nth === 0) return x
637
+ nth--;
638
+ }
639
+
640
+ index++;
641
+ }
642
+ }
584
643
  }
585
644
 
586
645
  function flatMap(fn) {
@@ -601,24 +660,25 @@ function flatten(list, input) {
601
660
  return willReturn
602
661
  }
603
662
 
604
- function groupBy(groupFn, list) {
605
- if (arguments.length === 1) {
606
- return _list => groupBy(groupFn, _list)
607
- }
663
+ function groupByFallback(groupFn, list) {
664
+ const result = {};
665
+ for (let i = 0; i < list.length; i++) {
666
+ const item = list[i];
667
+ const key = groupFn(item);
608
668
 
609
- const result = {};
610
- for (let i = 0; i < list.length; i++) {
611
- const item = list[i];
612
- const key = groupFn(item);
669
+ if (!result[key]) {
670
+ result[key] = [];
671
+ }
613
672
 
614
- if (!result[key]) {
615
- result[key] = [];
673
+ result[key].push(item);
616
674
  }
617
675
 
618
- result[key].push(item);
619
- }
676
+ return result
677
+ }
620
678
 
621
- return result
679
+
680
+ function groupBy(groupFn) {
681
+ return iterable => Object.groupBy ? Object.groupBy(iterable,groupFn) : groupByFallback(groupFn, iterable)
622
682
  }
623
683
 
624
684
  function head(listOrString) {
@@ -695,30 +755,60 @@ function innerJoin(pred, xs) {
695
755
  return ys => _filter(x => _includesWith(pred, x, ys), xs)
696
756
  }
697
757
 
758
+ const getOccurrences = input => input.match(/{{\s*.+?\s*}}/g);
759
+ const getOccurrenceProp = occurrence => occurrence.replace(/{{\s*|\s*}}/g, '');
760
+
761
+ const replace$1 = ({ inputHolder, prop, replacer }) => {
762
+ const regexBase = `{{${prop}}}`;
763
+ const regex = new RegExp(regexBase, 'g');
764
+ return inputHolder.replace(regex, replacer)
765
+ };
766
+
767
+ function interpolate(input) {
768
+ return templateInput => {
769
+ const occurrences = getOccurrences(input);
770
+ if (occurrences === null) {
771
+ return input
772
+ }
773
+ let inputHolder = input;
774
+
775
+ for (const occurrence of occurrences) {
776
+ const prop = getOccurrenceProp(occurrence);
777
+ inputHolder = replace$1({
778
+ inputHolder,
779
+ prop,
780
+ replacer: templateInput[prop],
781
+ });
782
+ }
783
+
784
+ return inputHolder
785
+ }
786
+ }
787
+
698
788
  function intersection(listA) {
699
- return listB =>filter(x => includes(x)(listA))(listB)
789
+ return listB => filter(x => includes(x)(listA))(listB)
700
790
  }
701
791
 
702
792
  function intersperse(separator) {
703
- return list => {
704
- let index = -1;
705
- const len = list.length;
706
- const willReturn = [];
793
+ return list => {
794
+ let index = -1;
795
+ const len = list.length;
796
+ const willReturn = [];
707
797
 
708
- while (++index < len) {
709
- if (index === len - 1) {
710
- willReturn.push(list[index]);
711
- } else {
712
- willReturn.push(list[index], separator);
798
+ while (++index < len) {
799
+ if (index === len - 1) {
800
+ willReturn.push(list[index]);
801
+ } else {
802
+ willReturn.push(list[index], separator);
803
+ }
713
804
  }
714
- }
715
805
 
716
- return willReturn
717
- }
806
+ return willReturn
807
+ }
718
808
  }
719
809
 
720
810
  function join(glue) {
721
- return list=> list.join(glue)
811
+ return list => list.join(glue)
722
812
  }
723
813
 
724
814
  function last(listOrString) {
@@ -746,34 +836,50 @@ function map(fn) {
746
836
  }
747
837
 
748
838
  function mapAsync(fn) {
749
- return async list => {
750
- const willReturn = [];
839
+ return async list => {
840
+ const willReturn = [];
751
841
  let i = 0;
752
842
  for (const a of list) {
753
843
  willReturn.push(await fn(a, i++));
754
844
  }
755
845
 
756
846
  return willReturn
757
- }
847
+ }
758
848
  }
759
849
 
760
- function mapObjectAsync(fn) {
761
- return async obj => {
850
+ function mapKeys(fn) {
851
+ return obj => {
762
852
  const willReturn = {};
763
- for (const prop in obj){
764
- willReturn[ prop ] = await fn(obj[ prop ], prop);
765
- }
766
-
853
+
854
+ Object.keys(obj).forEach(key => {
855
+ willReturn[fn(key, obj[key])] = obj[key];
856
+ });
857
+
767
858
  return willReturn
768
859
  }
769
860
  }
770
861
 
862
+ function mapObjectAsync(fn) {
863
+ return async obj => {
864
+ const willReturn = {};
865
+ for (const prop in obj) {
866
+ willReturn[prop] = await fn(obj[prop], prop);
867
+ }
868
+
869
+ return willReturn
870
+ }
871
+ }
872
+
873
+ function mapParallelAsync(fn) {
874
+ return async list => Promise.all(list.map((x, i) => fn(x, i)))
875
+ }
876
+
771
877
  function match(pattern) {
772
- return input => {
773
- const willReturn = input.match(pattern);
774
-
775
- return willReturn === null ? [] : willReturn
776
- }
878
+ return input => {
879
+ const willReturn = input.match(pattern);
880
+
881
+ return willReturn === null ? [] : willReturn
882
+ }
777
883
  }
778
884
 
779
885
  function maxBy(compareFn, x) {
@@ -793,66 +899,33 @@ function minBy(compareFn, x) {
793
899
  return y => (compareFn(y) < compareFn(x) ? y : x)
794
900
  }
795
901
 
796
- function createPath(path, delimiter = '.') {
797
- return typeof path === 'string'
798
- ? path.split(delimiter).map(x => (Number.isInteger(Number(x)) ? Number(x) : x))
799
- : path
800
- }
801
-
802
- function path(pathInput, obj) {
803
- if (arguments.length === 1) {
804
- return _obj => path(pathInput, _obj)
805
- }
806
-
807
- if (!obj) {
808
- return undefined
809
- }
810
- let willReturn = obj;
811
- let counter = 0;
812
-
813
- const pathArrValue = createPath(pathInput);
814
-
815
- while (counter < pathArrValue.length) {
816
- if (willReturn === null || willReturn === undefined) {
817
- return undefined
818
- }
819
- if (willReturn[pathArrValue[counter]] === null) {
820
- return undefined
902
+ function update(index, newValue) {
903
+ return list => {
904
+ const clone = cloneList$1(list);
905
+ if (index === -1) {
906
+ return clone.fill(newValue, index)
821
907
  }
822
908
 
823
- willReturn = willReturn[pathArrValue[counter]];
824
- counter++;
909
+ return clone.fill(newValue, index, index + 1)
825
910
  }
826
-
827
- return willReturn
828
911
  }
829
912
 
830
- function assoc(prop, newValue) {
831
- return obj => Object.assign({}, obj, { [prop]: newValue })
832
- }
833
-
834
- function modifyPathFn(pathInput, fn, obj) {
835
- const path$1 = createPath(pathInput);
836
- if (path$1.length === 1) {
837
- return {
838
- ...obj,
839
- [path$1[0]]: fn(obj[path$1[0]]),
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
- }
913
+ function modifyFn(property, fn, list) {
914
+ if (list[property] === undefined) {
915
+ return list
916
+ }
917
+ if (isArray(list)) {
918
+ return update(property, fn(list[property]))(list)
919
+ }
850
920
 
851
- return assoc(path$1[0], val)(obj)
921
+ return {
922
+ ...list,
923
+ [property]: fn(list[property]),
924
+ }
852
925
  }
853
926
 
854
- function modifyPath(pathInput, fn) {
855
- return obj => modifyPathFn(pathInput, fn, obj)
927
+ function modifyProp(property, fn) {
928
+ return obj => modifyFn(property, fn, obj)
856
929
  }
857
930
 
858
931
  function none(predicate) {
@@ -871,6 +944,22 @@ function objOf(key) {
871
944
  return value => ({ [key]: value })
872
945
  }
873
946
 
947
+ function objectIncludes(condition) {
948
+ return obj => {
949
+ const result = filterObject((conditionValue, conditionProp) =>
950
+ equals(conditionValue)(obj[conditionProp]),
951
+ )(condition);
952
+
953
+ return Object.keys(result).length === Object.keys(condition).length
954
+ }
955
+ }
956
+
957
+ function createPath(path, delimiter = '.') {
958
+ return typeof path === 'string'
959
+ ? path.split(delimiter).map(x => (Number.isInteger(Number(x)) ? Number(x) : x))
960
+ : path
961
+ }
962
+
874
963
  function _includes(x, list) {
875
964
  let index = -1;
876
965
  const { length } = list;
@@ -903,10 +992,29 @@ function omit(propsToOmit) {
903
992
  }
904
993
  }
905
994
 
906
- function partitionObject(predicate, iterable) {
995
+ function partition(predicate) {
996
+ return list => {
997
+ const yes = [];
998
+ const no = [];
999
+ let counter = -1;
1000
+
1001
+ while (counter++ < list.length - 1) {
1002
+ if (predicate(list[counter], counter)) {
1003
+ yes.push(list[counter]);
1004
+ } else {
1005
+ no.push(list[counter]);
1006
+ }
1007
+ }
1008
+
1009
+ return [yes, no]
1010
+ }
1011
+ }
1012
+
1013
+ function partitionObject(predicate) {
1014
+ return obj => {
907
1015
  const yes = {};
908
1016
  const no = {};
909
- Object.entries(iterable).forEach(([prop, value]) => {
1017
+ Object.entries(obj).forEach(([prop, value]) => {
910
1018
  if (predicate(value, prop)) {
911
1019
  yes[prop] = value;
912
1020
  } else {
@@ -916,31 +1024,73 @@ function partitionObject(predicate, iterable) {
916
1024
 
917
1025
  return [yes, no]
918
1026
  }
1027
+ }
919
1028
 
920
- function partitionArray(predicate, list, indexed = false) {
921
- const yes = [];
922
- const no = [];
923
- let counter = -1;
1029
+ function path(pathInput, obj) {
1030
+ if (arguments.length === 1) {
1031
+ return _obj => path(pathInput, _obj)
1032
+ }
924
1033
 
925
- while (counter++ < list.length - 1) {
926
- if (indexed ? predicate(list[counter], counter) : predicate(list[counter])) {
927
- yes.push(list[counter]);
928
- } else {
929
- no.push(list[counter]);
1034
+ if (!obj) {
1035
+ return undefined
1036
+ }
1037
+ let willReturn = obj;
1038
+ let counter = 0;
1039
+
1040
+ const pathArrValue = createPath(pathInput);
1041
+
1042
+ while (counter < pathArrValue.length) {
1043
+ if (willReturn === null || willReturn === undefined) {
1044
+ return undefined
1045
+ }
1046
+ if (willReturn[pathArrValue[counter]] === null) {
1047
+ return undefined
930
1048
  }
1049
+
1050
+ willReturn = willReturn[pathArrValue[counter]];
1051
+ counter++;
931
1052
  }
932
1053
 
933
- return [yes, no]
1054
+ return willReturn
934
1055
  }
935
1056
 
936
- function partition(predicate) {
937
- return iterable => {
938
- if (!isArray(iterable)) {
939
- return partitionObject(predicate, iterable)
940
- }
941
-
942
- return partitionArray(predicate, iterable)
943
- }
1057
+ /**
1058
+ * Source:
1059
+ * https://github.com/denoland/std/blob/main/collections/permutations.ts
1060
+ */
1061
+ function permutations(inputArray) {
1062
+ const result = [];
1063
+ const array = cloneList$1(inputArray);
1064
+ const k = array.length;
1065
+ if (k === 0) {
1066
+ return result;
1067
+ }
1068
+
1069
+ const c = new Array(k).fill(0);
1070
+
1071
+ result.push([...array]);
1072
+
1073
+ let i = 1;
1074
+
1075
+ while (i < k) {
1076
+ if (c[i] < i) {
1077
+ if (i % 2 === 0) {
1078
+ [array[0], array[i]] = [array[i], array[0]];
1079
+ } else {
1080
+ [array[c[i]], array[i]] = [array[i], array[c[i]]];
1081
+ }
1082
+
1083
+ result.push([...array]);
1084
+
1085
+ c[i] += 1;
1086
+ i = 1;
1087
+ } else {
1088
+ c[i] = 0;
1089
+ i += 1;
1090
+ }
1091
+ }
1092
+
1093
+ return result;
944
1094
  }
945
1095
 
946
1096
  function pick(propsToPick) {
@@ -1063,30 +1213,35 @@ function pipe(...inputs) {
1063
1213
  }
1064
1214
 
1065
1215
  async function pipeAsync(input, ...fnList) {
1066
- let willReturn = input;
1067
- for (const fn of fnList) {
1068
- const initialResult = fn(willReturn);
1069
- willReturn = type(initialResult) === 'Promise' ? await initialResult : initialResult;
1070
- }
1071
- return willReturn
1216
+ let willReturn = input;
1217
+ for (const fn of fnList) {
1218
+ const initialResult = fn(willReturn);
1219
+ willReturn =
1220
+ type(initialResult) === 'Promise' ? await initialResult : initialResult;
1221
+ }
1222
+ return willReturn
1072
1223
  }
1073
1224
 
1074
1225
  function pluck(property) {
1075
- return list => {
1076
- const willReturn = [];
1226
+ return list => {
1227
+ const willReturn = [];
1077
1228
 
1078
- list.forEach(x => {
1079
- if (x[property] !== undefined) {
1080
- willReturn.push(x[property]);
1081
- }
1082
- });
1229
+ list.forEach(x => {
1230
+ if (x[property] !== undefined) {
1231
+ willReturn.push(x[property]);
1232
+ }
1233
+ });
1083
1234
 
1084
- return willReturn
1085
- }
1235
+ return willReturn
1236
+ }
1086
1237
  }
1087
1238
 
1088
1239
  function prepend(x) {
1089
- return list=> [x].concat(list)
1240
+ return list => [x].concat(list)
1241
+ }
1242
+
1243
+ function prop(searchProperty) {
1244
+ return obj => (obj ? obj[searchProperty] : undefined)
1090
1245
  }
1091
1246
 
1092
1247
  function propEq(valueToMatch, propToFind) {
@@ -1110,30 +1265,49 @@ function propOr(defaultValue, property) {
1110
1265
  }
1111
1266
 
1112
1267
  function propSatisfies(predicate, property) {
1113
- return obj => predicate(prop(property))
1268
+ return obj => predicate(obj[property])
1114
1269
  }
1115
1270
 
1116
- function range(start){
1117
- return end => {
1118
- if (Number.isNaN(Number(start)) || Number.isNaN(Number(end))){
1119
- throw new TypeError('Both arguments to range must be numbers')
1120
- }
1271
+ function range(start) {
1272
+ return end => {
1273
+ if (Number.isNaN(Number(start)) || Number.isNaN(Number(end))) {
1274
+ throw new TypeError('Both arguments to range must be numbers')
1275
+ }
1121
1276
 
1122
- if (end < start) return []
1277
+ if (end <= start) {
1278
+ return []
1279
+ }
1123
1280
 
1124
- const len = end - start;
1125
- const willReturn = Array(len);
1281
+ const len = end - start;
1282
+ const willReturn = Array(len);
1126
1283
 
1127
- for (let i = 0; i < len; i++){
1128
- willReturn[ i ] = start + i;
1129
- }
1284
+ for (let i = 0; i < len + 1; i++) {
1285
+ willReturn[i] = start + i;
1286
+ }
1130
1287
 
1131
- return willReturn
1132
- }
1288
+ return willReturn
1289
+ }
1133
1290
  }
1134
1291
 
1135
- function reject(predicate) {
1136
- return list => filter(x => !predicate(x))
1292
+ function rangeDescending(start) {
1293
+ return end => {
1294
+ if (Number.isNaN(Number(start)) || Number.isNaN(Number(end))) {
1295
+ throw new TypeError('Both arguments to range must be numbers')
1296
+ }
1297
+
1298
+ if (end >= start) {
1299
+ return []
1300
+ }
1301
+
1302
+ const len = start - end;
1303
+ const willReturn = Array(len);
1304
+
1305
+ for (let i = 0; i < len + 1; i++) {
1306
+ willReturn[i] = start - i;
1307
+ }
1308
+
1309
+ return willReturn
1310
+ }
1137
1311
  }
1138
1312
 
1139
1313
  function replace(pattern, replacer) {
@@ -1147,30 +1321,60 @@ function replaceItemAtIndex(index, replaceFn) {
1147
1321
  return list
1148
1322
  }
1149
1323
 
1150
- const clone = cloneList(list);
1324
+ const clone = cloneList$1(list);
1151
1325
  clone[actualIndex] = replaceFn(clone[actualIndex]);
1152
1326
 
1153
1327
  return clone
1154
1328
  }
1155
1329
  }
1156
1330
 
1157
- function sort(sortFn){
1158
- return list => cloneList(list).sort(sortFn)
1331
+ function shuffle(listInput) {
1332
+ const list = cloneList(listInput);
1333
+ let counter = list.length;
1334
+ while (counter > 0) {
1335
+ const index = Math.floor(Math.random() * counter);
1336
+ counter--;
1337
+ const temp = list[counter];
1338
+ list[counter] = list[index];
1339
+ list[index] = temp;
1340
+ }
1341
+
1342
+ return list
1159
1343
  }
1160
1344
 
1161
- function sortBy(sortFn){
1162
- return list => {
1163
- const clone = cloneList(list);
1345
+ function sort(sortFn) {
1346
+ return list => cloneList$1(list).sort(sortFn)
1347
+ }
1164
1348
 
1165
- return clone.sort((a, b) => {
1166
- const aSortResult = sortFn(a);
1167
- const bSortResult = sortFn(b);
1349
+ function sortBy(sortFn) {
1350
+ return list => {
1351
+ const clone = cloneList$1(list);
1168
1352
 
1169
- if (aSortResult === bSortResult) return 0
1353
+ return clone.sort((a, b) => {
1354
+ const aSortResult = sortFn(a);
1355
+ const bSortResult = sortFn(b);
1170
1356
 
1171
- return aSortResult < bSortResult ? -1 : 1
1172
- })
1357
+ if (aSortResult === bSortResult) {
1358
+ return 0
1359
+ }
1360
+
1361
+ return aSortResult < bSortResult ? -1 : 1
1362
+ })
1363
+ }
1173
1364
  }
1365
+
1366
+ function sortObject(predicate) {
1367
+ return obj => {
1368
+ const keys = Object.keys(obj);
1369
+ const sortedKeys = sort((a, b) => predicate(a, b, obj[a], obj[b]))(keys);
1370
+
1371
+ const toReturn = {};
1372
+ sortedKeys.forEach(singleKey => {
1373
+ toReturn[singleKey] = obj[singleKey];
1374
+ });
1375
+
1376
+ return toReturn
1377
+ }
1174
1378
  }
1175
1379
 
1176
1380
  function sortHelper(a, b, listOfSortingFns) {
@@ -1185,37 +1389,37 @@ function sortHelper(a, b, listOfSortingFns) {
1185
1389
  }
1186
1390
 
1187
1391
  function sortWith(listOfSortingFns) {
1188
- return list => {
1189
- if (Array.isArray(list) === false) {
1190
- return []
1191
- }
1392
+ return list => {
1393
+ if (Array.isArray(list) === false) {
1394
+ return []
1395
+ }
1192
1396
 
1193
- const clone = list.slice();
1194
- clone.sort((a, b) => sortHelper(a, b, listOfSortingFns));
1397
+ const clone = list.slice();
1398
+ clone.sort((a, b) => sortHelper(a, b, listOfSortingFns));
1195
1399
 
1196
- return clone
1197
- }
1400
+ return clone
1401
+ }
1198
1402
  }
1199
1403
 
1200
- function split(separator){
1201
- return str => str.split(separator)
1404
+ function split(separator) {
1405
+ return str => str.split(separator)
1202
1406
  }
1203
1407
 
1204
1408
  function splitEvery(sliceLength) {
1205
- return list => {
1206
- if (sliceLength < 1) {
1207
- throw new Error('First argument to splitEvery must be a positive integer')
1208
- }
1409
+ return list => {
1410
+ if (sliceLength < 1) {
1411
+ throw new Error('First argument to splitEvery must be a positive integer')
1412
+ }
1209
1413
 
1210
- const willReturn = [];
1211
- let counter = 0;
1414
+ const willReturn = [];
1415
+ let counter = 0;
1212
1416
 
1213
- while (counter < list.length) {
1214
- willReturn.push(list.slice(counter, (counter += sliceLength)));
1215
- }
1417
+ while (counter < list.length) {
1418
+ willReturn.push(list.slice(counter, (counter += sliceLength)));
1419
+ }
1216
1420
 
1217
- return willReturn
1218
- }
1421
+ return willReturn
1422
+ }
1219
1423
  }
1220
1424
 
1221
1425
  function symmetricDifference(x) {
@@ -1261,24 +1465,24 @@ function takeLast(numberOfItems) {
1261
1465
  }
1262
1466
 
1263
1467
  function takeLastWhile(predicate) {
1264
- return input => {
1265
- if (input.length === 0) {
1266
- return input
1267
- }
1268
-
1269
- const toReturn = [];
1270
- let counter = input.length;
1271
-
1272
- while (counter) {
1273
- const item = input[--counter];
1274
- if (!predicate(item)) {
1275
- break
1276
- }
1277
- toReturn.push(item);
1278
- }
1279
-
1280
- return toReturn.reverse()
1281
- }
1468
+ return input => {
1469
+ if (input.length === 0) {
1470
+ return input
1471
+ }
1472
+
1473
+ const toReturn = [];
1474
+ let counter = input.length;
1475
+
1476
+ while (counter) {
1477
+ const item = input[--counter];
1478
+ if (!predicate(item)) {
1479
+ break
1480
+ }
1481
+ toReturn.push(item);
1482
+ }
1483
+
1484
+ return toReturn.reverse()
1485
+ }
1282
1486
  }
1283
1487
 
1284
1488
  function takeWhile(predicate) {
@@ -1298,15 +1502,15 @@ function takeWhile(predicate) {
1298
1502
  }
1299
1503
 
1300
1504
  function tap(fn) {
1301
- return x => {
1302
- fn(x);
1505
+ return x => {
1506
+ fn(x);
1303
1507
 
1304
- return x
1305
- }
1508
+ return x
1509
+ }
1306
1510
  }
1307
1511
 
1308
1512
  function test(pattern) {
1309
- return str => str.search(pattern) !== -1
1513
+ return str => str.search(pattern) !== -1
1310
1514
  }
1311
1515
 
1312
1516
  function tryCatch(fn, fallback) {
@@ -1321,7 +1525,7 @@ function tryCatch(fn, fallback) {
1321
1525
 
1322
1526
  function union(x) {
1323
1527
  return y => {
1324
- const toReturn = cloneList(x);
1528
+ const toReturn = cloneList$1(x);
1325
1529
 
1326
1530
  y.forEach(yInstance => {
1327
1531
  if (!includes(yInstance)(x)) {
@@ -1385,11 +1589,11 @@ function uniq(list) {
1385
1589
  }
1386
1590
 
1387
1591
  function uniqBy(fn) {
1388
- return list => {
1389
- const set = new _Set();
1592
+ return list => {
1593
+ const set = new _Set();
1390
1594
 
1391
- return list.filter(item => set.checkUniqueness(fn(item)))
1392
- }
1595
+ return list.filter(item => set.checkUniqueness(fn(item)))
1596
+ }
1393
1597
  }
1394
1598
 
1395
1599
  function includesWith(predicate, target, list) {
@@ -1408,20 +1612,20 @@ function includesWith(predicate, target, list) {
1408
1612
  }
1409
1613
 
1410
1614
  function uniqWith(predicate) {
1411
- return list => {
1412
- let index = -1;
1413
- const willReturn = [];
1615
+ return list => {
1616
+ let index = -1;
1617
+ const willReturn = [];
1414
1618
 
1415
- while (++index < list.length) {
1416
- const value = list[index];
1619
+ while (++index < list.length) {
1620
+ const value = list[index];
1417
1621
 
1418
- if (!includesWith(predicate, value, willReturn)) {
1419
- willReturn.push(value);
1622
+ if (!includesWith(predicate, value, willReturn)) {
1623
+ willReturn.push(value);
1624
+ }
1420
1625
  }
1421
- }
1422
1626
 
1423
- return willReturn
1424
- }
1627
+ return willReturn
1628
+ }
1425
1629
  }
1426
1630
 
1427
1631
  function unless(predicate, whenFalseFn) {
@@ -1443,17 +1647,6 @@ function unwind(property) {
1443
1647
  }
1444
1648
  }
1445
1649
 
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
1650
  function when(predicate, whenTrueFn) {
1458
1651
  return input => {
1459
1652
  if (!predicate(input)) {
@@ -1484,4 +1677,119 @@ function zipWith(fn, x) {
1484
1677
  )
1485
1678
  }
1486
1679
 
1487
- export { _arity, _includes, _indexOf, _lastIndexOf, all, allPass, any, anyPass, append, checkObjectWithSpec, complement, concat, count, countBy, defaultTo, drop, dropLast, dropLastWhile, dropWhile, eqBy, eqProps, equals, equalsFn, evolve, evolveFn, excludes, filter, filterObject, find, findIndex, findLast, findLastIndex, flatMap, flatten, groupBy, head, includes, indexOf, init, innerJoin, intersection, intersperse, join, last, lastIndexOf, map, mapAsync, mapObject, mapObjectAsync, match, maxBy, merge, mergeTypes, minBy, modifyPath, none, objOf, omit, partition, partitionArray, partitionObject, path, pick, pipe, pipeAsync, pluck, prepend, prop, propEq, propOr, propSatisfies, range, reduce, reject, replace, replaceItemAtIndex, sort, sortBy, sortWith, split, splitEvery, symmetricDifference, tail, take, takeLast, takeLastWhile, takeWhile, tap, test, tryCatch, type, union, uniq, uniqBy, uniqWith, unless, unwind, update, when, zip, zipWith };
1680
+ exports._arity = _arity;
1681
+ exports._includes = _includes;
1682
+ exports._indexOf = _indexOf;
1683
+ exports._lastIndexOf = _lastIndexOf;
1684
+ exports.addProp = addProp;
1685
+ exports.all = all;
1686
+ exports.allPass = allPass;
1687
+ exports.any = any;
1688
+ exports.anyPass = anyPass;
1689
+ exports.append = append;
1690
+ exports.ascend = ascend;
1691
+ exports.checkObjectWithSpec = checkObjectWithSpec;
1692
+ exports.compact = compact;
1693
+ exports.complement = complement;
1694
+ exports.concat = concat;
1695
+ exports.count = count;
1696
+ exports.countBy = countBy;
1697
+ exports.createCompareFunction = createCompareFunction;
1698
+ exports.createObjectFromKeys = createObjectFromKeys;
1699
+ exports.defaultTo = defaultTo;
1700
+ exports.descend = descend;
1701
+ exports.drop = drop;
1702
+ exports.dropLast = dropLast;
1703
+ exports.dropLastWhile = dropLastWhile;
1704
+ exports.dropWhile = dropWhile;
1705
+ exports.eqBy = eqBy;
1706
+ exports.eqProps = eqProps;
1707
+ exports.equals = equals;
1708
+ exports.equalsFn = equalsFn;
1709
+ exports.evolve = evolve;
1710
+ exports.excludes = excludes;
1711
+ exports.filter = filter;
1712
+ exports.filterObject = filterObject;
1713
+ exports.find = find;
1714
+ exports.findIndex = findIndex;
1715
+ exports.findLast = findLast;
1716
+ exports.findLastIndex = findLastIndex;
1717
+ exports.findNth = findNth;
1718
+ exports.flatMap = flatMap;
1719
+ exports.flatten = flatten;
1720
+ exports.groupBy = groupBy;
1721
+ exports.groupByFallback = groupByFallback;
1722
+ exports.head = head;
1723
+ exports.includes = includes;
1724
+ exports.indexOf = indexOf;
1725
+ exports.init = init;
1726
+ exports.innerJoin = innerJoin;
1727
+ exports.interpolate = interpolate;
1728
+ exports.intersection = intersection;
1729
+ exports.intersperse = intersperse;
1730
+ exports.join = join;
1731
+ exports.last = last;
1732
+ exports.lastIndexOf = lastIndexOf;
1733
+ exports.map = map;
1734
+ exports.mapAsync = mapAsync;
1735
+ exports.mapKeys = mapKeys;
1736
+ exports.mapObject = mapObject;
1737
+ exports.mapObjectAsync = mapObjectAsync;
1738
+ exports.mapParallelAsync = mapParallelAsync;
1739
+ exports.match = match;
1740
+ exports.maxBy = maxBy;
1741
+ exports.merge = merge;
1742
+ exports.mergeTypes = mergeTypes;
1743
+ exports.minBy = minBy;
1744
+ exports.modifyProp = modifyProp;
1745
+ exports.none = none;
1746
+ exports.objOf = objOf;
1747
+ exports.objectIncludes = objectIncludes;
1748
+ exports.omit = omit;
1749
+ exports.partition = partition;
1750
+ exports.partitionObject = partitionObject;
1751
+ exports.path = path;
1752
+ exports.permutations = permutations;
1753
+ exports.pick = pick;
1754
+ exports.pipe = pipe;
1755
+ exports.pipeAsync = pipeAsync;
1756
+ exports.pluck = pluck;
1757
+ exports.prepend = prepend;
1758
+ exports.prop = prop;
1759
+ exports.propEq = propEq;
1760
+ exports.propOr = propOr;
1761
+ exports.propSatisfies = propSatisfies;
1762
+ exports.range = range;
1763
+ exports.rangeDescending = rangeDescending;
1764
+ exports.reduce = reduce;
1765
+ exports.reject = reject;
1766
+ exports.rejectObject = rejectObject;
1767
+ exports.replace = replace;
1768
+ exports.replaceItemAtIndex = replaceItemAtIndex;
1769
+ exports.shuffle = shuffle;
1770
+ exports.sort = sort;
1771
+ exports.sortBy = sortBy;
1772
+ exports.sortObject = sortObject;
1773
+ exports.sortWith = sortWith;
1774
+ exports.split = split;
1775
+ exports.splitEvery = splitEvery;
1776
+ exports.symmetricDifference = symmetricDifference;
1777
+ exports.tail = tail;
1778
+ exports.take = take;
1779
+ exports.takeLast = takeLast;
1780
+ exports.takeLastWhile = takeLastWhile;
1781
+ exports.takeWhile = takeWhile;
1782
+ exports.tap = tap;
1783
+ exports.test = test;
1784
+ exports.tryCatch = tryCatch;
1785
+ exports.type = type;
1786
+ exports.union = union;
1787
+ exports.uniq = uniq;
1788
+ exports.uniqBy = uniqBy;
1789
+ exports.uniqWith = uniqWith;
1790
+ exports.unless = unless;
1791
+ exports.unwind = unwind;
1792
+ exports.update = update;
1793
+ exports.when = when;
1794
+ exports.zip = zip;
1795
+ exports.zipWith = zipWith;