Computing Statistics
Given a collection of data—a list of stock prices, a set of savings accounts, an array of daily temperature values for a city, for example—we often need to compute different values across the collection, like the average, min, max, and so on. Traditionally, using the imperative style approach, we’d first create a destination variable for the result and initialize it to some value. Then, as we iterate over the elements in the collection, we’d access the appropriate value for each element and update the destination variable accordingly, based on the computation we desire. The result is verbose code that’s often hard to understand and maintain and also difficult to parallelize if faster execution is necessary for a large collection ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access