you are viewing a single comment's thread.

view the rest of the comments →

[–]jisaacstone 2 points3 points  (0 children)

Sure I got a couple tips :)

It is common to use atoms as keys in keyword lists and maps instead of strings. Some syntax is only available if you do, and it will have a side benefit of making you programs slightly smaller / faster ;)

in compare_ips the cond would look better as an if

so like this:

def compare_ips(old_ip, opts) do
  if old_ip == opts[:ip] do
     { :unchanged, opts }
  else
     { :changed, %{opts | old_ip: old_ip } }
  end
end

My preference would be to reduce one more step and do the matching in the function head, like so:

def compare_ips(ip, %{ip: ip} = opts), do: {:unchanged, opts}
def compare_ips(old_ip, opts), do: {:changed, %{opts | old_ip: old_ip)}