Skip to content

Instantly share code, notes, and snippets.

@bmitch
Created June 25, 2017 14:56
Show Gist options
  • Save bmitch/cc531ea1136d58d578c6d93585ecf440 to your computer and use it in GitHub Desktop.
Save bmitch/cc531ea1136d58d578c6d93585ecf440 to your computer and use it in GitHub Desktop.
Parallel map
defmodule Parallel do
def pmap(collection, fun) do
me = self
collection
|> Enum.map(fn (elem) ->
spawn_link fn -> (send me, { self, fun.(elem) }) end
end)
|> Enum.map(fn (pid) ->
receive do { ^pid, result } -> result end
end)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment