Day 2: Functional Parallelism

Today we’ll continue our discussion of how functional programming helps with parallelism by looking at fold in more detail. But before we do that, we’ll look at parallelizing our Wikipedia word count.

One Page at a Time

In day 1 we saw that the map function creates a sequence by applying a function to each element of an input sequence in turn. But there’s no reason this has to happen serially—Clojure’s pmap function operates just like map, except that the function is applied in parallel. It’s semi-lazy, in that the parallel computation stays ahead of the consumption, but it won’t realize the entire result unless required.

We could, for example, convert our sequence of Wikipedia pages to a sequence ...

Get Seven Concurrency Models in Seven Weeks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.