O'Reilly logo

Seven Concurrency Models in Seven Weeks by Paul Butcher

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

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

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