Ashish Sharma
Ashish Sharma

Reputation: 672

How to update an entry inside a nested map in elixir

I want to update an entry in a heavy nested map. for example, in the below map I want to update city to "Noida". So how can I do that using library provided method? I know that there is a method get_in(map, [:key,...]) which is an easy method to fetch the value. Is there any similar kind of method for update?

input = %{
  name: "ashish",
  address: %{city: "delhi", country: "IN"}
}

expectation = %{
  name: "ashish",
  address: %{city: "noida", country: "IN"}
}

Upvotes: 1

Views: 894

Answers (1)

Ashish Sharma
Ashish Sharma

Reputation: 672

I find this link useful. The method I was looking for is Kernel.put_in/3.

put_in(input, [:address, :city], "noida")

Upvotes: 2

Related Questions