Run two observables sequentially, using result from first observable in second observable (question)
See original GitHub issueI’m probably overlooking something basic (sorry for that), this seems like it should be easy to do.
I have an Identifier class:
class Identifier {
int id;
String value;
Ticket[] tickets;
void setTickets(Ticket[] tickets) { this.tickets = tickets; }
}
And two separate API calls, (1) one for retrieving an identifier based on the identifier value (not the id), and (2) one for retrieving the tickets for an identifier using the identifier id:
Observable<Identifier> getIdentifier(String identifierValue);
Observable<Ticket[]> getTickets(int identifierId);
I want to create a method with the following signature:
Observable<Identifier> getIdentifierWithTickets(String identifierValue);
that combines the two observables to create an Observable<Identifier>
that:
- Retrieves the identifier based on the identifierValue.
- Retrieves the tickets for that identifier and assigns them to that identifier.
I’ve tried several operators but I can’t find the right one. The zipWith
operator runs the two observables in parallel so that didn’t work. I can perhaps use flatMap
but then I have to create a new observable that transforms Observable<Ticket[]>
into Observable<Identifier>
.
Like I said, I feel that I’m missing something very basic here, anyone please help.
Issue Analytics
- State:
- Created 9 years ago
- Comments:8 (2 by maintainers)
Probably we can make it a bit less convoluted, besides using map for obvious reason:
@akarnokd Thanks, I overlooked that. This simplifies things: