Everyone,
As a former Python addict, I recently found myself wanting to generate
a copy of an immutable object with only a single or a few values
changed. I tried to find an answer to this question but either my
search query skills or my lack of energy towards the end of my workday
hindered me.
Concretely, is there a nice idiomatic way to achieve the following.
immutable Foo
a::Int
b::Int
c::Int
end
o = Foo(17, 17, 17)
p = Foo(o.a, 4711, o.c)
When you know that you want to replace the value for `b`, without
having to explicitly enumerate the fields for which you simply want to
copy the previous value. For Python and named tuples, the operation
would be `_replace`. [1]
Regards,
Pontus
[1]:
https://docs.python.org/3/library/collections.html#collections.somenamedtuple._replace