itertools-ts icon indicating copy to clipboard operation
itertools-ts copied to clipboard

feat: Implement transform.divide() #75

Open DaBestCode opened this issue 4 months ago • 7 comments

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 

DaBestCode avatar Aug 30 '25 23:08 DaBestCode

Hi @DaBestCode! Please rebase your branch from dev and push it to fix github workflows.

Smoren avatar Aug 31 '25 13:08 Smoren

Hi @Smoren I have rebased and pushed the branch. Can you check if it passes the workflows.

DaBestCode avatar Aug 31 '25 18:08 DaBestCode

Hi @DaBestCode! Please fix issues in the review.

Smoren avatar Aug 31 '25 18:08 Smoren

Hi @Smoren I am so sorry I am fixing it. Please bare with me.

DaBestCode avatar Aug 31 '25 18:08 DaBestCode

@Smoren if you dont mind can you run this. I have removed the incorrect imports.

DaBestCode avatar Aug 31 '25 19:08 DaBestCode

Hi @DaBestCode Please add tests for all the new features in this PR, add docs to README and extend the CHANGLOG.md.

Smoren avatar Sep 02 '25 17:09 Smoren

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.

Smoren avatar Sep 06 '25 09:09 Smoren