O'Reilly logo

Reactive Android Programming by Tadas Subonis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Unwrapping lists

However, the resulting list is not something we really want to work with--the goal is to get to the YahooStockQuote object, which actually contains the data. That can be achieved with a .flatMap() call:

.toObservable().map(r -> r.getQuery().getResults().getQuote()).flatMap(r -> Observable.fromIterable(r))

Here, we create a new Observable from the resulting list and, using .flatMap(), we feed the result of the just created Observable into the original Observable. This might be confusing but, basically, we've transformed one item of the List<YahooStockQuote> type into many items of the YahooStockQuote type. The .flatMap() operator will be covered more in the later chapters.

Instead of r -> Observable.fromIterable(r), we can ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required