I\'ve got a pretty standard API pagination problem which you can handle with some simple recursion. Here\'s a fabricated example:
public Observable
Just an idea, why wouldnt you implement your own iterable that iterates over your pages and then make an observer from it?
Example :
Observable.from(new Iterable() {
@Override
public Iterator iterator() {
return new Iterator() {
@Override
public boolean hasNext() {
return hasNextPage(currentPageKey);
}
@Override
public T next() {
page = getNextPage(currentPageKey);
currentPageKey = page.getKey();
return page;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
});
a more elegant way would be to make your page manager (the scanner variable in your code example i believe) implement iterable and write the iteration logic there.