Andro
Andro

Reputation: 65

Emit every time 50 items out of a huge list

I have a List of more then 1000 items. I want to create API call on the OnNext every 50 items each time.

I tried scan and window operators but it didn't work for some reason.

Thanks for your help.

Upvotes: 0

Views: 64

Answers (1)

akarnokd
akarnokd

Reputation: 70007

There is an operator called every in the Extensions project:

Flowable.range(1, 5)
.compose(FlowableTransformers.<Integer>every(2))
.test()
.assertResult(2, 4);

or you can use buffer(50) and take the last element of the buffer:

Flowable.range(1, 1024)
.buffer(50)
.filter(list -> list.size() == 50)
.map(list -> list.get(49))
.subscribe(System.out::println);

Upvotes: 3

Related Questions