This chapter covers
- The internal details of persistent data structures
- The time and memory efficiency of persistent data structures
- Using persistent data structures in an application
In Part 1, we illustrated how to manage the state of a system without mutating data, where immutability is maintained 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 so-called persistent data structures.
There exist efficient implementations of persistent data structures for most programming languages via third-party libraries.
It’s at the university that Theo meets Joe this time. When Theo asks Joe if today’s topic is academic in nature, Joe tells him that the use of persistent data structures only became possible in programming languages following a discovery by a computer researcher named Phil Bagwell in 2001.[7] In 2007, Rich Hickey, the creator of Clojure, used this discovery as the foundation of persistent data structures in Clojure. Unveiling the secrets of these data structures to Theo in a university classroom is a way for Joe to honor the memory of Phil Bagwell who unfortunately passed away in 2012.
When they get to the university classroom, Joe starts the conversation with a question.