"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDefault = exports.modify = void 0;
const PromiseUtil_1 = require("../PromiseUtil");
/**
 * Modifies a {@link SetMultiMap} in place by removing and adding the requested entries.
 * Removals happen before additions.
 *
 * @param map - Map to start from.
 * @param options - {@link ModifyOptions} describing the necessary changes.
 */
function modify(map, options) {
    for (const key of options.remove ?? []) {
        map.delete(key);
    }
    for (const [key, val] of options.add ?? []) {
        map.add(key, val);
    }
    return map;
}
exports.modify = modify;
function getDefault(map, key, defaultFn) {
    const value = map.get(key);
    if (value) {
        return value;
    }
    return (0, PromiseUtil_1.resolvePromiseOrValue)(defaultFn(), (val) => {
        map.set(key, val);
        return val;
    });
}
exports.getDefault = getDefault;
//# sourceMappingURL=MapUtil.js.map