I have an Observable whose emitted item I need for the next Observable but I can't use flatMap() because the method I need to call in the Subscriber needs the result of both Observables.
service.getToken(code)
.subscribe(new Action1<Token>() {
@Override
public void call(Token token) {
service.getProfile(token.getAccessToken())
.subscribe(
new Action1<Profile>() {
@Override
public void call(Profile profile) {
createAccount(token, profile);
}
});
}
});
Any better approach then this?
Use the flatMap that takes a second Func2:
service.getToken()
.flatMap(token -> service.getProfile(token.getAccessToken()),
(token, profile) -> { createAccount(token, profile); return true; })
.subscribe(v -> { }, Throwable::printStackTrace)
Thank you for the quick response, that's a far better approach!
Most helpful comment
Use the
flatMapthat takes a secondFunc2: