Skip to content

Instantly share code, notes, and snippets.

@santosh79
Last active May 20, 2016 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save santosh79/e90ee89af75735bf73ded9f669ed1348 to your computer and use it in GitHub Desktop.
Save santosh79/e90ee89af75735bf73ded9f669ed1348 to your computer and use it in GitHub Desktop.
def pmap(coll, func) do
tasks = coll |>
Enum.map(fn(item) ->
Task.async(fn -> func.(item) end)
end) |> Enum.map(fn(task) ->
Task.await(task)
end)
end
@lucidstack
Copy link

lucidstack commented May 20, 2016

And if you don't need to be too explicit... 😀

def pmap(coll, func) do
  coll
  |> Enum.map(&Task.async(fn -> func.(&1) end)) 
  |> Enum.map(&Task.await/1)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment