collectable
Version:
An all-you-can-eat buffet of high-performance immutable/persistent data structures
25 lines (23 loc) • 990 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@collectable/core");
const map_1 = require("@collectable/map");
const internals_1 = require("../internals");
function setIn(path, value, collection) {
core_1.batch.start();
collection = setDeep(collection, path, 0, value);
core_1.batch.end();
return collection;
}
exports.setIn = setIn;
function setDeep(collection, path, keyidx, value) {
var key = path[keyidx], type;
core_1.batch.start();
if (core_1.isCollection(collection) && (type = collection['@@type'], internals_1.isIndexable(type)) && type.verifyKey(key, collection)) {
return keyidx === path.length - 1
? type.set(key, value, collection)
: type.update(key, c => setDeep(c, path, keyidx + 1, value), collection);
}
return map_1.fromArray([[key, keyidx === path.length - 1 ? value : setDeep(void 0, path, keyidx + 1, value)]]);
}
//# sourceMappingURL=set.js.map
;