Romain Romain - 29 days ago 11
Java Question

Call void method and pass trought arguments RxJava

I'm looking for a better to do this :

mRestService.login(email, password) // Login user in
.flatMap(user -> Observable.zip(
mRestService.start(user._token), // Start his session
Observable.just(user),
(v, u) -> (User) u // Pass user throught
))
.subscribe(user -> {
}, throwable -> {
});


But I coudn't come up with something better.

Answer

the start method on the mRestService perform a side effect. So you can use doOnNext method which is here for this sort of side effect.

 mRerstService.login(email, password)
              .doOnNext(u -> mRestService.start(user._token))
              .subscribe();