Skip to content

Instantly share code, notes, and snippets.

@dav11d
Created September 21, 2017 13:24
Show Gist options
  • Save dav11d/7249097935102cc2a9b5adc4d1eb4b19 to your computer and use it in GitHub Desktop.
Save dav11d/7249097935102cc2a9b5adc4d1eb4b19 to your computer and use it in GitHub Desktop.
def atc([], new_item) do
[new_item]
end
def atc([h = %{product_id: id, size: size, quantity: old_quantity}|t], %{product_id: id, quantity: growth, size: size}) do
[%{h | quantity: old_quantity + growth}|t]
end
def atc([h|t], new_item) do
[h|atc(t, new_item)]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment