rambda 10.0.1 → 10.2.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.
@@ -119,6 +119,15 @@
119
119
  }
120
120
  }
121
121
 
122
+ function assertType(fn) {
123
+ return (x) => {
124
+ if (fn(x)) {
125
+ return x
126
+ }
127
+ throw new Error('type assertion failed in R.assertType')
128
+ }
129
+ }
130
+
122
131
  function checkObjectWithSpec(conditions) {
123
132
  return input => {
124
133
  let shouldProceed = true;
@@ -194,6 +203,10 @@
194
203
  return y => (typeof x === 'string' ? `${x}${y}` : [...x, ...y])
195
204
  }
196
205
 
206
+ function convertToType(x) {
207
+ return x
208
+ }
209
+
197
210
  function count(predicate) {
198
211
  return list => {
199
212
  if (!isArray(list)) {
@@ -1001,6 +1014,66 @@
1001
1014
  }
1002
1015
  }
1003
1016
 
1017
+ function createPath(path, delimiter = '.') {
1018
+ return typeof path === 'string'
1019
+ ? path.split(delimiter).map(x => (Number.isInteger(Number(x)) ? Number(x) : x))
1020
+ : path
1021
+ }
1022
+
1023
+ function path(pathInput) {
1024
+ return (obj) => {
1025
+ if (!obj) {
1026
+ return undefined
1027
+ }
1028
+ let willReturn = obj;
1029
+ let counter = 0;
1030
+
1031
+ const pathArrValue = createPath(pathInput);
1032
+
1033
+ while (counter < pathArrValue.length) {
1034
+ if (willReturn === null || willReturn === undefined) {
1035
+ return undefined
1036
+ }
1037
+ if (willReturn[pathArrValue[counter]] === null) {
1038
+ return undefined
1039
+ }
1040
+
1041
+ willReturn = willReturn[pathArrValue[counter]];
1042
+ counter++;
1043
+ }
1044
+
1045
+ return willReturn
1046
+ }
1047
+ }
1048
+
1049
+ function assoc(prop, newValue) {
1050
+ return obj => Object.assign({}, obj, { [prop]: newValue })
1051
+ }
1052
+
1053
+ function modifyPathFn(pathInput, fn, obj) {
1054
+ const path$1 = createPath(pathInput);
1055
+ if (path$1.length === 1) {
1056
+ return {
1057
+ ...obj,
1058
+ [path$1[0]]: fn(obj[path$1[0]]),
1059
+ }
1060
+ }
1061
+ if (path(path$1)(obj) === undefined) {
1062
+ return obj
1063
+ }
1064
+
1065
+ const val = modifyPathFn(Array.prototype.slice.call(path$1, 1), fn, obj[path$1[0]]);
1066
+ if (val === obj[path$1[0]]) {
1067
+ return obj
1068
+ }
1069
+
1070
+ return assoc(path$1[0], val)(obj)
1071
+ }
1072
+
1073
+ function modifyPath(pathInput, fn) {
1074
+ return obj => modifyPathFn(pathInput, fn, obj)
1075
+ }
1076
+
1004
1077
  function update(index, newValue) {
1005
1078
  return list => {
1006
1079
  const clone = cloneList(list);
@@ -1056,12 +1129,6 @@
1056
1129
  }
1057
1130
  }
1058
1131
 
1059
- function createPath(path, delimiter = '.') {
1060
- return typeof path === 'string'
1061
- ? path.split(delimiter).map(x => (Number.isInteger(Number(x)) ? Number(x) : x))
1062
- : path
1063
- }
1064
-
1065
1132
  function _includes(x, list) {
1066
1133
  let index = -1;
1067
1134
  const { length } = list;
@@ -1128,32 +1195,6 @@
1128
1195
  }
1129
1196
  }
1130
1197
 
1131
- function path(pathInput) {
1132
- return (obj) => {
1133
- if (!obj) {
1134
- return undefined
1135
- }
1136
- let willReturn = obj;
1137
- let counter = 0;
1138
-
1139
- const pathArrValue = createPath(pathInput);
1140
-
1141
- while (counter < pathArrValue.length) {
1142
- if (willReturn === null || willReturn === undefined) {
1143
- return undefined
1144
- }
1145
- if (willReturn[pathArrValue[counter]] === null) {
1146
- return undefined
1147
- }
1148
-
1149
- willReturn = willReturn[pathArrValue[counter]];
1150
- counter++;
1151
- }
1152
-
1153
- return willReturn
1154
- }
1155
- }
1156
-
1157
1198
  function pathSatisfies(fn, pathInput) {
1158
1199
  return obj => Boolean(fn(path(pathInput)(obj)))
1159
1200
  }
@@ -1791,10 +1832,12 @@
1791
1832
  exports.anyPass = anyPass;
1792
1833
  exports.append = append;
1793
1834
  exports.ascend = ascend;
1835
+ exports.assertType = assertType;
1794
1836
  exports.checkObjectWithSpec = checkObjectWithSpec;
1795
1837
  exports.compact = compact;
1796
1838
  exports.complement = complement;
1797
1839
  exports.concat = concat;
1840
+ exports.convertToType = convertToType;
1798
1841
  exports.count = count;
1799
1842
  exports.countBy = countBy;
1800
1843
  exports.createCompareFunction = createCompareFunction;
@@ -1848,6 +1891,7 @@
1848
1891
  exports.mergeTypes = mergeTypes;
1849
1892
  exports.minBy = minBy;
1850
1893
  exports.modifyItemAtIndex = modifyItemAtIndex;
1894
+ exports.modifyPath = modifyPath;
1851
1895
  exports.modifyProp = modifyProp;
1852
1896
  exports.none = none;
1853
1897
  exports.objOf = objOf;