|
@@ -43,7 +43,7 @@ const getKeyWithCheck = (x, key) =>
|
|
isMapKey(key) ? x.has(key.key) ? {value: x.get(key.key)} : null :
|
|
isMapKey(key) ? x.has(key.key) ? {value: x.get(key.key)} : null :
|
|
x.hasOwnProperty(key) ? {value: x[key]} : null;
|
|
x.hasOwnProperty(key) ? {value: x[key]} : null;
|
|
|
|
|
|
-const chain = (list, stop, step) => (function worker (index) {
|
|
|
|
|
|
+const chain = list => step => stop => (function worker (index) {
|
|
return index >= list.length ? stop : step(list[index], worker(index + 1));
|
|
return index >= list.length ? stop : step(list[index], worker(index + 1));
|
|
})(0);
|
|
})(0);
|
|
|
|
|
|
@@ -53,20 +53,21 @@ const copyOnModification = (obj, key, value, modifierFn) => {
|
|
};
|
|
};
|
|
|
|
|
|
const atPathBeginningWith = prefix => (...keyDescriptions) => {
|
|
const atPathBeginningWith = prefix => (...keyDescriptions) => {
|
|
- const keys = parseKeysInto(keyDescriptions, [...prefix]);
|
|
|
|
-
|
|
|
|
- return Object.assign(atPathBeginningWith(keys), {
|
|
|
|
- get: obj => keys.reduce(getKey, obj),
|
|
|
|
-
|
|
|
|
- put: val => chain(keys, () => val, (key, next) => x =>
|
|
|
|
|
|
+ const keys = parseKeysInto(keyDescriptions, [...prefix]),
|
|
|
|
+ keyChain = chain(keys),
|
|
|
|
+ putChain = keyChain((key, next) => x =>
|
|
copyOnModification(x, key, getKey(x, key), next)
|
|
copyOnModification(x, key, getKey(x, key), next)
|
|
),
|
|
),
|
|
-
|
|
|
|
- map: fn => chain(keys, fn, (key, next) => x => {
|
|
|
|
|
|
+ mapChain = keyChain((key, next) => x => {
|
|
const valueWithCheck = getKeyWithCheck(x, key);
|
|
const valueWithCheck = getKeyWithCheck(x, key);
|
|
if (valueWithCheck == null) return x;
|
|
if (valueWithCheck == null) return x;
|
|
return copyOnModification(x, key, valueWithCheck.value, next);
|
|
return copyOnModification(x, key, valueWithCheck.value, next);
|
|
- })
|
|
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return Object.assign(atPathBeginningWith(keys), {
|
|
|
|
+ get: obj => keys.reduce(getKey, obj),
|
|
|
|
+ put: val => putChain(() => val),
|
|
|
|
+ map: mapChain
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
|