Skip to content

Instantly share code, notes, and snippets.

@fishcakez
Forked from pmarreck/default_args_fun.exs
Last active August 29, 2015 14:19
Show Gist options
  • Save fishcakez/ae40d2667ea9d414caf3 to your computer and use it in GitHub Desktop.
Save fishcakez/ae40d2667ea9d414caf3 to your computer and use it in GitHub Desktop.
def concurrent_factorial(range, worker_pool_by_nodenames \\ worker_pool_by_nodenames)
def concurrent_factorial(%Range{first: start, last: finish}, worker_pool_by_nodenames) do
pmap(split_range_of_numbers(start..finish), fn(range) -> range |> Enum.reduce(&(&1*&2)) end, worker_pool_by_nodenames) |>
Enum.reduce(&(&1*&2))
end
def concurrent_factorial(n, worker_pool_by_nodenames) when is_integer(n) and n > 0 do
concurrent_factorial(1..n, worker_pool_by_nodenames)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment