Created
June 25, 2017 14:56
-
-
Save bmitch/cc531ea1136d58d578c6d93585ecf440 to your computer and use it in GitHub Desktop.
Parallel map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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