Persistent/Immutable Data Structures

In the pure immutable design for the net work-years example, we asked each person to create a new total. As we go through the chain of people, a new number is created while an old number is discarded—not a big deal since the numbers are relatively small.

The data we have to deal with may not be that small; it could be a list, tree, or matrix. We may need to work with objects that represent a boiler, a satellite, a city, and so on. We won’t naively copy these large objects over and over because that’ll lead to poor performance. Immutable or persistent data structures come to the rescue here.

Persistent[9] data structures version their values so older and newer values stay around or persist over time without ...

Get Programming Concurrency on the JVM now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.