import * as tsplus_module_1 from "@tsplus/stdlib/collections/HashMap/empty";
import * as tsplus_module_2 from "@tsplus/stdlib/collections/HashMap/_internal/hashMap";
import * as tsplus_module_3 from "@tsplus/stdlib/collections/HashMap/update";
import * as tsplus_module_4 from "@tsplus/stdlib/collections/HashMap/set";
import * as tsplus_module_5 from "@tsplus/stdlib/collections/Chunk/reduce";
import * as tsplus_module_6 from "@effect/core/stream/Sink/operations/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.
 *
 * @tsplus static ets/Sink/Ops collectAllToMap
 */

export function collectAllToMap(key, f, __tsplusTrace) {
  return tsplus_module_6.foldLeftChunks(() => tsplus_module_1.empty(), (acc, as) => tsplus_module_5.reduce_(as, acc, (acc, a) => {
    const k = key(a);
    return tsplus_module_2.has_(acc, k) ? tsplus_module_3.update_(acc, k, v => f(v, a)) : tsplus_module_4.set_(acc, k, a);
  }), __tsplusTrace);
}
//# sourceMappingURL=collectAllToMap.mjs.map