I am trying to implement a simple sliding window function in RxJava2, but struggling to do what I want.
My goal is to take a stream of objects, i.e.
["a", "b", "c", "d", "e"]
and apply a sliding window which will return the elements adjacent to each element.
I.e resulting in:
["a", "b"]
["a", "b", "c"]
["b", "c", "d"]
["c", "d", "e"]
["d", "e"].
I.E.
a----------------b----------------c----------------d----------------e
↓ ↓ ↓ ↓ ↓
↓ ↓ ↓ ↓ ↓
↓ ↓ ↓ ↓ ↓
↓ ↓ ↓ ↓ ↓
["a", "b"] ["a", "b", "c"] ["b", "c", "d"] ["c", "d", "e"] ["d", "e"]
I can't seem to figure out how to make this happen. A Google Groups post seems like it is on the right track, but doesn't quite get the result I need: https://groups.google.com/forum/#!topic/rxjava/k-U5BijXinU
Any ideas?