rambda 10.1.0 → 10.3.0

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.
@@ -539,6 +539,53 @@
539
539
  return b => equalsFn(a, b)
540
540
  }
541
541
 
542
+ class _Set {
543
+ constructor() {
544
+ this.set = new Set();
545
+ this.items = {};
546
+ }
547
+
548
+ checkUniqueness(item) {
549
+ const type$1 = type(item);
550
+ if (['Null', 'Undefined', 'NaN'].includes(type$1)) {
551
+ if (type$1 in this.items) {
552
+ return false
553
+ }
554
+ this.items[type$1] = true;
555
+
556
+ return true
557
+ }
558
+ if (!['Object', 'Array'].includes(type$1)) {
559
+ const prevSize = this.set.size;
560
+ this.set.add(item);
561
+
562
+ return this.set.size !== prevSize
563
+ }
564
+
565
+ if (!(type$1 in this.items)) {
566
+ this.items[type$1] = [item];
567
+
568
+ return true
569
+ }
570
+
571
+ if (_indexOf(item, this.items[type$1]) === -1) {
572
+ this.items[type$1].push(item);
573
+
574
+ return true
575
+ }
576
+
577
+ return false
578
+ }
579
+ }
580
+
581
+ function duplicateBy(fn) {
582
+ return list => {
583
+ const set = new _Set();
584
+
585
+ return list.filter(item => !set.checkUniqueness(fn(item)))
586
+ }
587
+ }
588
+
542
589
  function eqBy(fn, a) {
543
590
  return b => equalsFn(fn(a), fn(b))
544
591
  }
@@ -590,6 +637,21 @@
590
637
  return iterable => !includes(valueToFind)(iterable)
591
638
  }
592
639
 
640
+ function filterAsync(predicate) {
641
+ return async list => {
642
+ const willReturn = [];
643
+ let index = 0;
644
+ for (const x of list) {
645
+ if (await predicate(x, index)) {
646
+ willReturn.push(list[index]);
647
+ }
648
+ index++;
649
+ }
650
+
651
+ return willReturn
652
+ }
653
+ }
654
+
593
655
  function filterObject(predicate) {
594
656
  return obj => {
595
657
  const willReturn = {};
@@ -802,6 +864,21 @@
802
864
  return listOrString[0]
803
865
  }
804
866
 
867
+ function indexBy(property){
868
+ return list => {
869
+ const toReturn = {};
870
+ for (let i = 0; i < list.length; i++){
871
+ const item = list[ i ];
872
+ const key = item[property];
873
+ if(key !== undefined){
874
+ toReturn[ key ] = item;
875
+ }
876
+ }
877
+
878
+ return toReturn
879
+ }
880
+ }
881
+
805
882
  function indexOf(valueToFind) {
806
883
  return list => _indexOf(valueToFind, list)
807
884
  }
@@ -940,8 +1017,8 @@
940
1017
  return async list => {
941
1018
  const willReturn = [];
942
1019
  let i = 0;
943
- for (const a of list) {
944
- willReturn.push(await fn(a, i++));
1020
+ for (const x of list) {
1021
+ willReturn.push(await fn(x, i++));
945
1022
  }
946
1023
 
947
1024
  return willReturn
@@ -975,6 +1052,17 @@
975
1052
  return async list => Promise.all(list.map((x, i) => fn(x, i)))
976
1053
  }
977
1054
 
1055
+ function mapPropObject(fn, prop) {
1056
+ return obj => {
1057
+ if (!Array.isArray(obj[prop])) return obj
1058
+
1059
+ return {
1060
+ ...obj,
1061
+ [prop]: obj[prop].map(fn)
1062
+ }
1063
+ }
1064
+ }
1065
+
978
1066
  function match(pattern) {
979
1067
  return input => {
980
1068
  const willReturn = input.match(pattern);
@@ -1014,6 +1102,66 @@
1014
1102
  }
1015
1103
  }
1016
1104
 
1105
+ function createPath(path, delimiter = '.') {
1106
+ return typeof path === 'string'
1107
+ ? path.split(delimiter).map(x => (Number.isInteger(Number(x)) ? Number(x) : x))
1108
+ : path
1109
+ }
1110
+
1111
+ function path(pathInput) {
1112
+ return (obj) => {
1113
+ if (!obj) {
1114
+ return undefined
1115
+ }
1116
+ let willReturn = obj;
1117
+ let counter = 0;
1118
+
1119
+ const pathArrValue = createPath(pathInput);
1120
+
1121
+ while (counter < pathArrValue.length) {
1122
+ if (willReturn === null || willReturn === undefined) {
1123
+ return undefined
1124
+ }
1125
+ if (willReturn[pathArrValue[counter]] === null) {
1126
+ return undefined
1127
+ }
1128
+
1129
+ willReturn = willReturn[pathArrValue[counter]];
1130
+ counter++;
1131
+ }
1132
+
1133
+ return willReturn
1134
+ }
1135
+ }
1136
+
1137
+ function assoc(prop, newValue) {
1138
+ return obj => Object.assign({}, obj, { [prop]: newValue })
1139
+ }
1140
+
1141
+ function modifyPathFn(pathInput, fn, obj) {
1142
+ const path$1 = createPath(pathInput);
1143
+ if (path$1.length === 1) {
1144
+ return {
1145
+ ...obj,
1146
+ [path$1[0]]: fn(obj[path$1[0]]),
1147
+ }
1148
+ }
1149
+ if (path(path$1)(obj) === undefined) {
1150
+ return obj
1151
+ }
1152
+
1153
+ const val = modifyPathFn(Array.prototype.slice.call(path$1, 1), fn, obj[path$1[0]]);
1154
+ if (val === obj[path$1[0]]) {
1155
+ return obj
1156
+ }
1157
+
1158
+ return assoc(path$1[0], val)(obj)
1159
+ }
1160
+
1161
+ function modifyPath(pathInput, fn) {
1162
+ return obj => modifyPathFn(pathInput, fn, obj)
1163
+ }
1164
+
1017
1165
  function update(index, newValue) {
1018
1166
  return list => {
1019
1167
  const clone = cloneList(list);
@@ -1069,12 +1217,6 @@
1069
1217
  }
1070
1218
  }
1071
1219
 
1072
- function createPath(path, delimiter = '.') {
1073
- return typeof path === 'string'
1074
- ? path.split(delimiter).map(x => (Number.isInteger(Number(x)) ? Number(x) : x))
1075
- : path
1076
- }
1077
-
1078
1220
  function _includes(x, list) {
1079
1221
  let index = -1;
1080
1222
  const { length } = list;
@@ -1141,32 +1283,6 @@
1141
1283
  }
1142
1284
  }
1143
1285
 
1144
- function path(pathInput) {
1145
- return (obj) => {
1146
- if (!obj) {
1147
- return undefined
1148
- }
1149
- let willReturn = obj;
1150
- let counter = 0;
1151
-
1152
- const pathArrValue = createPath(pathInput);
1153
-
1154
- while (counter < pathArrValue.length) {
1155
- if (willReturn === null || willReturn === undefined) {
1156
- return undefined
1157
- }
1158
- if (willReturn[pathArrValue[counter]] === null) {
1159
- return undefined
1160
- }
1161
-
1162
- willReturn = willReturn[pathArrValue[counter]];
1163
- counter++;
1164
- }
1165
-
1166
- return willReturn
1167
- }
1168
- }
1169
-
1170
1286
  function pathSatisfies(fn, pathInput) {
1171
1287
  return obj => Boolean(fn(path(pathInput)(obj)))
1172
1288
  }
@@ -1422,6 +1538,17 @@
1422
1538
  return str => str.replace(pattern, replacer)
1423
1539
  }
1424
1540
 
1541
+ function replaceAll(patterns, replacer) {
1542
+ return input => {
1543
+ let text = input;
1544
+ patterns.forEach(singlePattern => {
1545
+ text = text.replace(singlePattern, replacer);
1546
+ });
1547
+
1548
+ return text
1549
+ }
1550
+ }
1551
+
1425
1552
  function shuffle(listInput) {
1426
1553
  const list = cloneList(listInput);
1427
1554
  let counter = list.length;
@@ -1652,45 +1779,6 @@
1652
1779
  }
1653
1780
  }
1654
1781
 
1655
- class _Set {
1656
- constructor() {
1657
- this.set = new Set();
1658
- this.items = {};
1659
- }
1660
-
1661
- checkUniqueness(item) {
1662
- const type$1 = type(item);
1663
- if (['Null', 'Undefined', 'NaN'].includes(type$1)) {
1664
- if (type$1 in this.items) {
1665
- return false
1666
- }
1667
- this.items[type$1] = true;
1668
-
1669
- return true
1670
- }
1671
- if (!['Object', 'Array'].includes(type$1)) {
1672
- const prevSize = this.set.size;
1673
- this.set.add(item);
1674
-
1675
- return this.set.size !== prevSize
1676
- }
1677
-
1678
- if (!(type$1 in this.items)) {
1679
- this.items[type$1] = [item];
1680
-
1681
- return true
1682
- }
1683
-
1684
- if (_indexOf(item, this.items[type$1]) === -1) {
1685
- this.items[type$1].push(item);
1686
-
1687
- return true
1688
- }
1689
-
1690
- return false
1691
- }
1692
- }
1693
-
1694
1782
  function uniq(list) {
1695
1783
  const set = new _Set();
1696
1784
  const willReturn = [];
@@ -1820,6 +1908,7 @@
1820
1908
  exports.dropLast = dropLast;
1821
1909
  exports.dropLastWhile = dropLastWhile;
1822
1910
  exports.dropWhile = dropWhile;
1911
+ exports.duplicateBy = duplicateBy;
1823
1912
  exports.eqBy = eqBy;
1824
1913
  exports.eqProps = eqProps;
1825
1914
  exports.equals = equals;
@@ -1827,6 +1916,7 @@
1827
1916
  exports.evolve = evolve;
1828
1917
  exports.excludes = excludes;
1829
1918
  exports.filter = filter;
1919
+ exports.filterAsync = filterAsync;
1830
1920
  exports.filterObject = filterObject;
1831
1921
  exports.find = find;
1832
1922
  exports.findIndex = findIndex;
@@ -1841,6 +1931,7 @@
1841
1931
  exports.groupByFallback = groupByFallback;
1842
1932
  exports.head = head;
1843
1933
  exports.includes = includes;
1934
+ exports.indexBy = indexBy;
1844
1935
  exports.indexOf = indexOf;
1845
1936
  exports.init = init;
1846
1937
  exports.innerJoin = innerJoin;
@@ -1857,12 +1948,14 @@
1857
1948
  exports.mapObject = mapObject;
1858
1949
  exports.mapObjectAsync = mapObjectAsync;
1859
1950
  exports.mapParallelAsync = mapParallelAsync;
1951
+ exports.mapPropObject = mapPropObject;
1860
1952
  exports.match = match;
1861
1953
  exports.maxBy = maxBy;
1862
1954
  exports.merge = merge;
1863
1955
  exports.mergeTypes = mergeTypes;
1864
1956
  exports.minBy = minBy;
1865
1957
  exports.modifyItemAtIndex = modifyItemAtIndex;
1958
+ exports.modifyPath = modifyPath;
1866
1959
  exports.modifyProp = modifyProp;
1867
1960
  exports.none = none;
1868
1961
  exports.objOf = objOf;
@@ -1887,6 +1980,7 @@
1887
1980
  exports.reject = reject;
1888
1981
  exports.rejectObject = rejectObject;
1889
1982
  exports.replace = replace;
1983
+ exports.replaceAll = replaceAll;
1890
1984
  exports.shuffle = shuffle;
1891
1985
  exports.sort = sort;
1892
1986
  exports.sortBy = sortBy;