Have you looked at pyrsistent for immutable/functional/persistent/copy-on-write data structures in Python?<div><div><br></div><div><a href="https://github.com/tobgu/pyrsistent/">https://github.com/tobgu/pyrsistent/</a></div><div><br></div><div>(freeze() / thaw())</div><div><br></div><div>... e.g. List and Dict NamedTuple values are not immutable (because append() and update() still work)</div><div><br>On Sunday, January 22, 2017, Soni L. <<a href="mailto:fakedme%2Bpy@gmail.com">fakedme+py@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I've been thinking of an Immutable Builder pattern and an operator to go with it. Since the builder would be immutable, this wouldn't work:<br>
<br>
long_name = mkbuilder()<br>
long_name.seta(a)<br>
long_name.setb(b)<br>
y = long_name.build()<br>
<br>
Instead, you'd need something more like this:<br>
<br>
long_name = mkbuilder()<br>
long_name = long_name.seta(a)<br>
long_name = long_name.setb(b)<br>
y = long_name.build()<br>
<br>
Or we could add an operator to simplify it:<br>
<br>
long_name = mkbuilder()<br>
long_name .= seta(a)<br>
long_name .= setb(b)<br>
y = long_name.build()<br>
<br>
(Yes, I'm aware you can x = mkbuilder().seta(a).setb(b), then y = x.build(). But that doesn't work if you wanna "fork" the builder. Some builders, like a builder for network connections of some sort, would work best if they were immutable/forkable.)<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a>Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/codeofco<wbr>nduct/</a><br>
</blockquote></div></div>