I've an Observable that returns a single Cursor instance (Observable<Cursor>). I'm trying to utilize ContentObservable.fromCursor to obtain every cursor's row in onNext callback.
One of the solutions I've figured out is such construction:
ContentObservable.fromCursor(cursorObservable.toBlocking().first())
.subscribe(cursor -> {
// map to object
// add to outer collection
}, e -> {}, () -> {
// do something with list of objects (outer collection)
});
This looks rather like a hack because of toBlocking().first(), but it works. I don't like it because most of the processing is done in onNext callback and we've to create outer collection to hold the intermediate results.
I wanted to use it like this:
cursorObservable.map(ContentObservable::fromCursor)
.map(fromCursor -> fromCursor.toBlocking().first())
.map(/* map to object */)
.toList()
.subscribe(objects -> {
// do something with list of objects
}
This still utilizes toBlocking().first() and doesn't work because once the fromCursor observable has finished the cursor is closed so there's no way to map it to object. Is there a better way to flatten Observable<Observable<Cursor>> to Observable<Cursor>?