"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.collectAllToMap = void 0;
// ets_tracing: off
const CK = __importStar(require("../../../Collections/Immutable/Chunk"));
const HM = __importStar(require("../../../Collections/Immutable/HashMap"));
const FoldLeftChunks = __importStar(require("./foldLeftChunks"));
/**
 * A sink that collects all of its inputs into a map. The keys are extracted from inputs
 * using the keying function `key`; if multiple inputs use the same key, they are merged
 * using the `f` function.
 */
function collectAllToMap(key, f) {
    return FoldLeftChunks.foldLeftChunks(HM.make(), (acc, as) => CK.reduce_(as, acc, (acc, a) => {
        const k = key(a);
        if (HM.has_(acc, k)) {
            return HM.update_(acc, k, (v) => f(v, a));
        }
        else {
            return HM.set_(acc, k, a);
        }
    }));
}
exports.collectAllToMap = collectAllToMap;
//# sourceMappingURL=collectAllToMap.js.map