@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.
31 lines • 941 B
JavaScript
/**
* @module Collection
*/
import {} from "../../../../collection/contracts/_module-exports.js";
import { resolveInvokable } from "../../../../utilities/_module-exports.js";
/**
* @internal
*/
export class AsyncCountByIterable {
collection;
callback;
constructor(collection, callback = (item) => item) {
this.collection = collection;
this.callback = callback;
}
async *[Symbol.asyncIterator]() {
const map = new Map();
for await (const [index, item] of this.collection.entries()) {
const key = await resolveInvokable(this.callback)(item, index, this.collection);
if (!map.has(key)) {
map.set(key, 0);
}
const counter = map.get(key);
if (counter !== undefined) {
map.set(key, counter + 1);
}
}
yield* map;
}
}
//# sourceMappingURL=async-count-by-iterable.js.map