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.

38 lines 1.09 kB
/** * @module Collection */ import {} from "../../../../collection/contracts/_module-exports.js"; /** * @internal */ export class ChunkIterable { collection; chunkSize; makeCollection; constructor(collection, chunkSize, makeCollection) { this.collection = collection; this.chunkSize = chunkSize; this.makeCollection = makeCollection; } *[Symbol.iterator]() { const array = []; let currentChunkSize = 0; let isFirstIteration = true; for (const item of this.collection) { currentChunkSize %= this.chunkSize; const isFilled = currentChunkSize === 0; if (!isFirstIteration && isFilled) { yield this.makeCollection(array); array.length = 0; } array.push(item); currentChunkSize++; isFirstIteration = false; } const hasRest = currentChunkSize !== 0; if (hasRest) { yield this.makeCollection(array); } } } //# sourceMappingURL=chunk-iterable.js.map