feat: Implement transform.divide() #75
This PR adds support for dividing an iterable/async iterable into evenly sized chunks while preserving order. Implements the following methods:
transform.divide()
transform.divideAsync()
Stream.divide()
AsyncStream.divide()
Example Usage
Stream.of([1, 2, 3, 4]).divide(2).toArray();
// => [[1, 2], [3, 4]]
for await (const chunk of AsyncStream.of([1, 2, 3, 4]).divide(2)) {
console.log(chunk);
}
// Logs: [1, 2], then [3, 4]
Details
transform.divide: generator function that splits a synchronous iterable/iterator into n smaller arrays.
transform.divideAsync: async generator function that splits an asynchronous iterable/iterator into n smaller arrays.
Stream.divide: integrates transform.divide into the Stream class.
AsyncStream.divide: integrates transform.divideAsync into the AsyncStream class. #75
Hi @DaBestCode! Please rebase your branch from dev and push it to fix github workflows.
Hi @Smoren I have rebased and pushed the branch. Can you check if it passes the workflows.
Hi @DaBestCode! Please fix issues in the review.
Hi @Smoren I am so sorry I am fixing it. Please bare with me.
@Smoren if you dont mind can you run this. I have removed the incorrect imports.
Hi @DaBestCode Please add tests for all the new features in this PR, add docs to README and extend the CHANGLOG.md.
Hi @DaBestCode There is a lot of formatting changes in README and CHANGELOG files. Can you roll back these changes please? And please resolve the conflicts.