|
@@ -47,21 +47,21 @@ 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);
|
|
|
|
|
|
-const copyOnModification = (obj, key, value, modifierFn) => {
|
|
|
|
- const modified = modifierFn(value);
|
|
|
|
- return value === modified ? obj : copyWith(key, modified)(obj);
|
|
|
|
|
|
+const id = x => x;
|
|
|
|
+
|
|
|
|
+const modifier = (key, value, valueModifier) => {
|
|
|
|
+ const modified = valueModifier(value);
|
|
|
|
+ return value === modified ? id : copyWith(key, modified);
|
|
};
|
|
};
|
|
|
|
|
|
const atPathBeginningWith = prefix => (...keyDescriptions) => {
|
|
const atPathBeginningWith = prefix => (...keyDescriptions) => {
|
|
const keys = parseKeysInto(keyDescriptions, [...prefix]),
|
|
const keys = parseKeysInto(keyDescriptions, [...prefix]),
|
|
keyChain = chain(keys),
|
|
keyChain = chain(keys),
|
|
- putChain = keyChain((key, next) => x =>
|
|
|
|
- copyOnModification(x, key, getKey(x, key), next)
|
|
|
|
- ),
|
|
|
|
|
|
+ putChain = keyChain((key, next) => x => modifier(key, getKey(x, key), next)(x)),
|
|
mapChain = keyChain((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 modifier(key, valueWithCheck.value, next)(x);
|
|
});
|
|
});
|
|
|
|
|
|
return Object.assign(atPathBeginningWith(keys), {
|
|
return Object.assign(atPathBeginningWith(keys), {
|