you can also use map cons, if you would like for your code to crash when you try to assign a nonexistent field, lets you catch errors in tests (how good is your test coverage? lol)
defmodule S do
defstruct [x: 0]
def do_something(val = %S{}) do
%{val | y: "oops"}
end
end
will crash on do_something. Whenever it’s a struct, I prefer using map cons for that bailout behaviour.






















