I am new to Rxjava. I am following a video tutorial where there is a code example that calls an API and gets string result using flatmap. Below is the code:
twitchAPI.getTopGamesObservable()
.flatMap(new Func1<Twitch, Observable<Top>>() {
@Override
public Observable<Top> call(Twitch twitch) {
Observable<Top> rtnTop = Observable.from(twitch.getTop());
Log.d("LogRx", "Size for FROM:" + "\n");
return rtnTop;
}
})
.flatMap(new Func1<Top, Observable<String>>() {
@Override
public Observable<String> call(Top top) {
Log.d("LogRx", "Size for JUST:" + "\n");
return Observable.just(top.getGame().getName());
}
})
.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<String>() {
@Override
public void onCompleted() { }
@Override
public void onError(Throwable e) { }
@Override
public void onNext(String s) { Log.d("LogRx", s); }
});
But i am not really understanding the sequence of how this code works.
And the confusion is because of observable.from() & observable.just(). I know that observable.from() will give N emissions for a list and observable.just() will give 1 emissions(a list).
So, does it mean that the second flatMap is called N times because Observable.from() inside the first flatMap is emitting each item in the list each time. And for the second flatMap the onNext() of subscriber is called N times too(once for each call of 2nd flatmap)?