|
@@ -1,20 +1,20 @@
|
|
-function copyArrayWith (obj, key, value) {
|
|
|
|
|
|
+const copyArrayWith = (key, value) => obj => {
|
|
const result = obj == null ? [] : [...obj];
|
|
const result = obj == null ? [] : [...obj];
|
|
result[key] = value;
|
|
result[key] = value;
|
|
return result;
|
|
return result;
|
|
-}
|
|
|
|
|
|
+};
|
|
|
|
|
|
-function copyMapWith (obj, key, value) {
|
|
|
|
|
|
+const copyMapWith = (key, value) => obj => {
|
|
const result = obj == null ? new Map() : new Map(obj);
|
|
const result = obj == null ? new Map() : new Map(obj);
|
|
result.set(key, value);
|
|
result.set(key, value);
|
|
return result;
|
|
return result;
|
|
-}
|
|
|
|
|
|
+};
|
|
|
|
|
|
-function copyObjectWith (obj, key, value) {
|
|
|
|
|
|
+const copyObjectWith = (key, value) => obj => {
|
|
const result = obj == null ? {} : {...obj};
|
|
const result = obj == null ? {} : {...obj};
|
|
result[key] = value;
|
|
result[key] = value;
|
|
return result;
|
|
return result;
|
|
-}
|
|
|
|
|
|
+};
|
|
|
|
|
|
const isMapKey = key => typeof key === 'object' && key.isKeyInMap === true;
|
|
const isMapKey = key => typeof key === 'object' && key.isKeyInMap === true;
|
|
|
|
|
|
@@ -22,10 +22,10 @@ export const keyInMap = key => ({isKeyInMap: true, key});
|
|
|
|
|
|
export const kim = keyInMap;
|
|
export const kim = keyInMap;
|
|
|
|
|
|
-const copyWith = (obj, key, value) =>
|
|
|
|
- typeof key === 'number' ? copyArrayWith(obj, key, value) :
|
|
|
|
- isMapKey(key) ? copyMapWith(obj, key.key, value) :
|
|
|
|
- copyObjectWith(obj, key, value);
|
|
|
|
|
|
+const copyWith = (key, value) =>
|
|
|
|
+ typeof key === 'number' ? copyArrayWith(key, value) :
|
|
|
|
+ isMapKey(key) ? copyMapWith(key.key, value) :
|
|
|
|
+ copyObjectWith(key, value);
|
|
|
|
|
|
const constructKeys = function (keyDescriptions) {
|
|
const constructKeys = function (keyDescriptions) {
|
|
const keys = [];
|
|
const keys = [];
|
|
@@ -63,7 +63,7 @@ const chain = (list, stop, step) => (function worker (index) {
|
|
|
|
|
|
const copyOnModification = (obj, key, value, modifierFn) => {
|
|
const copyOnModification = (obj, key, value, modifierFn) => {
|
|
const modified = modifierFn(value);
|
|
const modified = modifierFn(value);
|
|
- return value === modified ? obj : copyWith(obj, key, modified);
|
|
|
|
|
|
+ return value === modified ? obj : copyWith(key, modified)(obj);
|
|
};
|
|
};
|
|
|
|
|
|
export const deepCopyOnWrite = (...keyDescriptions) => {
|
|
export const deepCopyOnWrite = (...keyDescriptions) => {
|