ElixirWeekly: The Elixir Community Newsletter, covering community news you easily miss, shared on ElixirStatus and the web, in one email every Thursday.
This article comprises of common Elixir coding techniques that you may or may not know.
A Jist of the Article
We usually encounter a situation like we expect a map has certain key and if not we need to send some default value.
Immediately, we will end up using
Map.has_key? like in the following way
currency = if(Map.has_key? price, "currency") do price["currency"] else "USD"
If you see any such lines in your code then it is time to refactor them as
currency = Map.get(price, "currency", "USD")
However, you can also take this to the next level like
currency = price["currency"] || "USD"