@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.
35 lines • 1.31 kB
JavaScript
/**
* @module Collection
*/
import {} from "../../../../collection/contracts/_module-exports.js";
import {} from "../../../../utilities/_module-exports.js";
/**
* @internal
*/
export class AsyncPadStartIterable {
collection;
maxLength;
fillItems;
makeCollection;
constructor(collection, maxLength, fillItems, makeCollection) {
this.collection = collection;
this.maxLength = maxLength;
this.fillItems = fillItems;
this.makeCollection = makeCollection;
}
async *[Symbol.asyncIterator]() {
const fillCollections = this.makeCollection(this.fillItems);
const fillSize = await fillCollections.size();
const size = await this.collection.size();
const repeat = Math.floor((this.maxLength - size) / fillSize);
let resultCollection = this.makeCollection([]);
for (let index = 0; index < repeat; index++) {
resultCollection = resultCollection.append(fillCollections);
}
const restAmount = this.maxLength - (repeat * fillSize + size);
resultCollection = resultCollection.append(fillCollections.slice(0, restAmount));
resultCollection = resultCollection.append(this.collection);
yield* resultCollection;
}
}
//# sourceMappingURL=async-pad-start-iterable.js.map