7 Immutability at scale with persistent data structures
In Part 1, we illustrated how to manage the state of a system without mutating data, where immutability is kept by constraining ourselves to manipulate the state only with immutable functions, leveraging structural sharing.
In the current chapter, we present a safer and more scalable way to preserve data immutability by representing data with persistent data structures. Persistent data structures prevents from data to be modified at the level of the data structure itself and allow us to create new versions of data efficiently, both in terms of computation and memory, no matter the data size.
There exist implementations of persistent data structures for most programming languages via third party libraries.