[erlang-questions] best way to update a nested map

Kenneth Lakin kennethlakin@REDACTED
Tue May 17 21:53:50 CEST 2016


On 05/17/2016 12:38 PM, Caragea Silviu wrote:
> M = #{ a => 1, c =>#{x => 1, y => 7}}.
> M1 = M#{c}#{y => 4711}.

AFAIK, you have to capture the nested map to update (rather than
replace) it:

M = #{ a => 1, c => #{x => 1, y => 7}}.
#{c := C} = M.
M1 = M#{c := C#{y := 4771}}.

The slide that lists the syntax you want to use (and the two proceeding
it) *appear* to be slides that describe possible future syntax. You must
currently use pattern matching or maps:get/2,3 to pluck out values from
a map.

This might be better to learn maps syntax from:
http://erlang.org/doc/reference_manual/expressions.html#id81479


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160517/ab5f6f8b/attachment.bin>


More information about the erlang-questions mailing list