You should be using maps. :P
*José Valim* www.plataformatec.com.br Skype: jv.ptec Founder and Director of R&D On Thu, Jul 28, 2016 at 5:35 PM, Michał Muskała <[email protected]> wrote: > > > 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. > -- 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/CAGnRm4KLZThT-tVtrwts8do-ejGAmdf2f%3DZ8rQ8%3De%2Bq4jpiuqQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
