🗓️Day 14
Sunday, 21 August 2022 - Day 14 of Exhort August 2022 - Exercism (My Elixir Journey)
Exercises
Boutique Inventory
Boutique Inventory in Elixir on Exercism | View my solution
Solution
Notes
Oh Zeus. I really struggled with this one. And it was so simple. I don't know why. Here's my accepted solution:
def increase_quantity(item, count) do
qbs = Map.new(item.quantity_by_size, fn {k, v} -> {k, v + count} end)
%{item | quantity_by_size: qbs }
endI was trying all sorts of irrelevant things 😬. I was also thrown off by the mention of Enum.into in README.md. I guess it was an alternative to Map.new?
For total_quantity/1, I used a different approach, while the exercise recommended Enum.reduce. It was the purpose of the exercise to teach you that. My initial implementation was:
item.quantity_by_size
|> Map.values
|> Enum.sumI think it's a little easier in the eyes, but I have no idea if it's slower as I am calling a Map function and then an Enum function. Whereas reduce/3 is one function.
Overall progress

Last updated