![](https://secure.gravatar.com/avatar/63ca18e130d527d0741f1da54bb129a7.jpg?s=120&d=mm&r=g)
Have you looked at pyrsistent for immutable/functional/persistent/copy-on-write data structures in Python? https://github.com/tobgu/pyrsistent/ (freeze() / thaw()) ... e.g. List and Dict NamedTuple values are not immutable (because append() and update() still work) On Sunday, January 22, 2017, Soni L. <fakedme+py@gmail.com> wrote:
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:
long_name = mkbuilder() long_name.seta(a) long_name.setb(b) y = long_name.build()
Instead, you'd need something more like this:
long_name = mkbuilder() long_name = long_name.seta(a) long_name = long_name.setb(b) y = long_name.build()
Or we could add an operator to simplify it:
long_name = mkbuilder() long_name .= seta(a) long_name .= setb(b) y = long_name.build()
(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.) _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/