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:

                .flatMap(new Func1<Twitch, Observable<Top>>() {
            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>>() {
            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>() {
            public void onCompleted() {     }

            public void onError(Throwable e) {    }

            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)?

Related posts

Recent Viewed