-
Notifications
You must be signed in to change notification settings - Fork 22
hw3 commit #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
base: master
Are you sure you want to change the base?
hw3 commit #22
Conversation
| test "counter using an agent" do | ||
| { :ok, counter } = Agent.start(fn -> 0 end) | ||
|
|
||
| value = Agent.get_and_update(counter,fn state -> {state, state + 1} 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.
No deduction, but watch out for layout—I'd like to see a space after commas.
|
|
||
| defmodule Ex02 do | ||
|
|
||
| @server CounterGlobal |
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.
-6
I'm being a little tough here, but the instructions asked you to use an agent for this, rather than writing your own GenServer.
+2
Then I'm being a softie because you wrote your own GenServer
| chunk_size = ( Enum.count( collection) / process_count ) |> round | ||
| chunks = Enum.chunk_every( collection, chunk_size) | ||
| fmap = &( Task.async( fn -> Enum.map( &1, function) end ) ) | ||
| tasks = Enum.map( chunks, fmap ) |
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.
-5 for style/complexity
I'm uncomfortable with the number of variables, and the general linear nature of this code.
I'd rather have seen something like:
defp into_chunks(collection, count) do
chunk_size = div(Enum.count( collection), count )
Enum.chunk_every( collection, chunk_size)
end
def pmap(collection, process_count, function) do
chunk_mapper = &( Task.async( fn -> Enum.map( &1, function) end ) )
collection
|> into_chunks(process_count)
|> Enum.map( chunk_mapper )
|> Enum.map( &( Task.await( &1 ) ) )
|> Enum.concat()
end
Michael Gilbert 44823653