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 of maps of ...
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