> On 28 Jul 2016, at 17:13, Peter Hamilton <
petergh...@gmail.com> wrote:
>
> Could we see some example usage?
My use case is basically something like that:
I have a struct with a field that holds a list of structs. Each of those nested structs has two fields: id and value. I want to insert a new value for a struct with a given id. For the sake of example, let’s say we work with plain maps:
id_to_update = 2
new_value = :d
map = %{nested: [%{value: :a, id: 1}, %{value: :b, id: 2}, %{value: :c, id: 3}], foo: :bar}
update_in(map, [:nested, Access.find(&(&
1.id == id_to_update)), :value], fn _ -> new_value end)
#=> %{parties: [%{value: :a, id: 1}, %{value: **:d**, id: 2}, %{value: :c, id: 3}], foo: :bar}
Michał.