UNPKG

@daiso-tech/core

Version:

The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.

33 lines 1.1 kB
/** * @module Collection */ import {} from "../../../../collection/contracts/_module-exports.js"; import { resolveInvokable, } from "../../../../utilities/_module-exports.js"; /** * @internal */ export class AsyncGroupByIterable { collection; selectFn; makeCollection; constructor(collection, selectFn = (item) => item, makeCollection) { this.collection = collection; this.selectFn = selectFn; this.makeCollection = makeCollection; } async *[Symbol.asyncIterator]() { const map = new Map(); for await (const [index, item] of this.collection.entries()) { const key = await resolveInvokable(this.selectFn)(item, index, this.collection); let array = map.get(key); if (array === undefined) { array = []; map.set(key, array); } array.push(item); map.set(key, array); } yield* this.makeCollection(map).map(([key, value]) => [key, this.makeCollection(value)]); } } //# sourceMappingURL=async-group-by-iterable.js.map