framework-js icon indicating copy to clipboard operation
framework-js copied to clipboard

Batching by amount should allow to adjust step size

Open f1ames opened this issue 4 years ago • 0 comments

Feature description

In v4 .batch() is a simple transform which groups chunks by a given number:

// input: [1,2,3,4,5,6,7,8,9,10]
// batch(amount)
.batch(2)  -> [1,2], [3,4], [5,6], ...

and in pre-v5 it accepts a callback but we plan to introduce batching by amount the same as v4 too.

Now, it could be extended by adding optional step param which will allow to change how chunks are grouped:

// input: [1,2,3,4,5,6,7,8,9,10]
// batch(amount, step = amount)
.batch(2)    -> [1,2], [3,4], [5,6], ...
.batch(2, 2) -> [1,2], [3,4], [5,6], ...
.batch(2, 1) -> [1,2], [2,3], [3,4], ...
.batch(3, 2) -> [1, 2, 3], [3, 4, 5], [5, 6, 7], ...

Use case

The use case is - creating a WindowStream out of any other stream with ability to decide how each window frame content is grouped. And in the context of the above proposal it could be:

anyStream.batch(3, 2).as(WindowStream)

f1ames avatar Dec 28 '21 10:12 f1ames