Pattern 19Focused Mutability


To use mutable data structures in small, performance-sensitive parts of a program hidden inside of a function while still using immutable data throughout the majority


Programming with performant, immutable data on machines that are built out of fundamentally mutable components, like main memory and disk, is almost magical. A whole host of technology has contributed to making it possible, especially on the JVM. Growing processor power and memory sizes make it increasingly unnecessary to squeeze every last drop of performance out of a machine.

Small, transient objects are cheap to create and to destroy, thanks to the JVM’s excellent generational garbage collector. Both Scala and Clojure use extremely ...

Get Functional Programming Patterns in Scala and Clojure now with O’Reilly online learning.

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