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

Financial stock quote Observable

We can start by extracting a Factory Method for the Observable that is responsible for the retrieval of financial stock quotes from Yahoo API using this:

Observable.interval(0, 5, TimeUnit.SECONDS)        .flatMapSingle(i -> yahooService.yqlQuery(query, env))        .map(r -> r.getQuery().getResults().getQuote())        .flatMap(Observable::fromIterable)        .map(StockUpdate::create)        .groupBy(stockUpdate -> stockUpdate.getStockSymbol())        .flatMap(groupObservable -> groupObservable.distinctUntilChanged())

This code can be extracted into a method:

createFinancialStockUpdateObservable()

This consists of the following:

private Observable<StockUpdate> createFinancialStockUpdateObservable(YahooService yahooService, String query, String ...

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