I am looking for a concise way of updating a nested value inside a record in Elm (0.18).
Given the following example:
person = { name = "Steven", address = { country = "Spain", city = "Barcelona" } }
I can update person.name to "Steve" using the following expression:
{ person | name = "Steve" }
However, I am looking for a way to update a nested value. For instance, I would like to update person.address.city to "Madrid". I tried the following:
{ person | address.city = "Madrid" }
{ person | address = { address | city = "Madrid" } }
{ person | address = { person.address | city = "Madrid" } }
The compiler rejects all these variations. The shortest valid option I see is:
let personAddress = person.address in { person | address = { personAddress | city = "Madrid" } }
This seems to be a bit too much code just to update a nested value, Do you know if there is a better/shorter way of achieving that?