> On 28 Jul 2016, at 17:13, Peter Hamilton <[email protected]> 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ł.
--
You received this message because you are subscribed to the Google Groups
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/44FFBC51-C3A7-44D4-B77A-5C2FB46CC36E%40muskala.eu.
For more options, visit https://groups.google.com/d/optout.
signature.asc
Description: Message signed with OpenPGP using GPGMail
