-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nicholas Crothers Submission #5
Conversation
range_to_enumerable(collection) | ||
|> splitmap(process_count) | ||
|> spawnchunks(function) | ||
|> receivechunks | ||
|> flatten_result | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
YES!
Thank you for structuring it like this...
def range_to_enumerable(range) do | ||
Enum.map(range, fn x -> x end) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Range is already enumerable. In fact, this function makes that assumption, as map
wouldn't work otherwise...
|
||
def spawnchunks(chunks, function) do | ||
me = self() | ||
Enum.map(chunks, fn chunk -> spawn(fn -> process(chunk, function, me) end) end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good name for the variable...
end | ||
|
||
def splitmap(enumerable, process_count) do | ||
Enum.chunk_every(enumerable, div(length(enumerable), process_count)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The div
here returns the wrong value (try it with 10 and 4).
-2
# « your code goes here» | ||
# You can give an agent a name by adding the | ||
# `name: @global_name` option to start_link | ||
{:ok, pid} = Agent.start_link(fn -> initial_value end, name: @global_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line generates a warning because pid
is unused.
Name: Nicholas Crothers
ID: 47330742