Created
September 15, 2014 05:29
-
-
Save edubkendo/506a716ed63742781ccb 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