1
votes

Is there an operator ( rxjava operator more specifically ), that would transform the source observable so that it would emit a list of 'n' newest items each time the source observable emits new item.

Something like:

---A-----B------C--------D-----------E------->

           bufferNewest(2)

---[A]---[A,B]--[B,C]----[C,D]-------[D,E]--->

If there is is not a default operator like this, what is the best way to implement such behavior? Thanks

1

1 Answers

2
votes

Hmm, I can't remember if the 2-parameter buffer(count,skip) method can do this. If it can't, use scan() to do this.