UNPKG

collectable

Version:

An all-you-can-eat buffet of high-performance immutable/persistent data structures

22 lines (20 loc) 865 B
import { isCollection, batch } from '@collectable/core'; import { fromArray } from '@collectable/map'; import { isIndexable } from '../internals'; export function setIn(path, value, collection) { batch.start(); collection = setDeep(collection, path, 0, value); batch.end(); return collection; } function setDeep(collection, path, keyidx, value) { var key = path[keyidx], type; batch.start(); if (isCollection(collection) && (type = collection['@@type'], 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 fromArray([[key, keyidx === path.length - 1 ? value : setDeep(void 0, path, keyidx + 1, value)]]); } //# sourceMappingURL=set.js.map