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

More FlatMap variations

There are a few more .flatMap() variations that we can use. Recall the following block:

Observable.interval(0, 5, TimeUnit.SECONDS)        .flatMap(                i -> yahooService.yqlQuery(query, env)                        .toObservable()        )

The .yqlQuery() call returns a Single type and thus cannot be used directly with .flatMap(), which expects to consume the Observable type. In this case, to work around that, we had to use the following to convert it to the Observable type:

.toObservable()

However, there is a better way. Instead of using .flatMap(), we can use .flatMapSingle() to do the same thing:

Observable.interval(0, 5, TimeUnit.SECONDS)        .flatMapSingle(i -> yahooService.yqlQuery(query, env))

.flatMapSingle() takes the Single type and automatically ...

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