July 2017
Intermediate to advanced
284 pages
6h 45m
English
Let’s put the parallel collection to a practical use. In Chapter 3, Scala and Functional Style, we looked at concise code to fetch and process stock prices from Yahoo. Let’s revisit that code and make it run parallel.
For this example, we’ll use the following tickers:
val tickers = List("AAPL", "AMD", "CSCO", "GOOG", "HPQ", "INTC", "MSFT", "ORCL")
The code to fetch the price and construct it into a StockPrice object is repeated from that chapter here.
| | case class StockPrice(ticker : String, price : Double) { |
| | def print = println("Top stock is " + ticker + " at price $" + price) |
| | } |
| | def getPrice(ticker : String) = { |
| | val url = s"http://download.finance.yahoo.com/d/quotes.csv?s=${ticker}&f=snbaopl1" ... |
Read now
Unlock full access