Reputation: 53
I am new to rx-java and may not be using it correctly, but this is what I am trying to do:
I have an Observable<String>
that stores some data in an external database and emits a String which is the path or key to the data that was stored.
I have a second Observable<Boolean>
that takes a String and puts it on a queue and emits whether that operation was successful.
I want to 'chain' these two Observables such that when the Observable<String>
emits a path, the Observable<Boolean>
puts it on a queue and returns whether it was successful. I want to end up with a single Observable that performs both of these operations.
I haven't been able to find any API methods that let me do what I want so I am starting to think that I am not using rx-java properly. It seems like I need to take my Observable<String>
and call .map() to turn it into an Observable<Boolean>
, but by doing this I am not able to use my original Observable<Boolean>
other than by just running it as a blocking method inside of map(), but it may as well just be a Callable at that point.
edit: seems like I should probably be using Singles rather than Observables as my Observables only need to emit one value before completing.
Upvotes: 2
Views: 618
Reputation: 12087
Looks like flatMap
is what you are looking for.
So you have:
Observable<String> data;
and method
Observable<Boolean> putOnQueue(String path);
Then you could do:
Observable<Boolean> result = data.flatMap(path -> putOnQueue(path));
Upvotes: 1