-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Closed
Labels
Description
Take the following contrived example:
Observable
.just("yo")
.flatMap(s -> Observable.range(0, 100))
.subscribe(integer -> Ln.d("Here's an Integer(%s), but how do I access that juicy String?", integer));
I often come up against this problem, where I'd like to act upon multiple chained streams. I can easily imagine a couple of ways to access both the String Observable and the Integer Observable within a downstream subscribe() or some other operator. One is pulling the String Observable into a variable and then accessing it within a lambda. Another is to do something like:
Observable
.just("yo")
.flatMap(s ->
Observable.combineLatest(
Observable.just(s),
Observable.range(0, 100),
Pair::new))
.subscribe(pair -> Ln.d("Here's an Integer(%s), and here's a juicy String(%s), but isn't this a little hard to follow and annoying?", pair.second, pair.first));
But this necessitates repackaging the original Observable with the dependent Observable into some more complex data structure.
There's gotta be a better way. Help?
bdelville, dsokolov, Sriharia, maeb, denys-vasylenko and 21 more