But even if you refuse to mutate objects, you’ll still need to deal with transformations to data. In a purely immutable world, this means you have to create a whole new object each time something changes, which can slow things down and eat up memory, making functional programming seem inefficient.
That’s where immutable data structures come in to save the day—and time and space. Also called persistent data structures, they help you efficiently make new “modified” versions of immutable objects by reusing parts of the old object that you don’t need to change. By making immutability efficient, such data structures are fantastic for functional programming and play a central role in functional languages such as Clojure.
Anjana Vakil is and engineering learning and development lead at Mapbox. Anjana suffers from a debilitating case of curiosity, which led her from philosophy to English teaching to computational linguistics to software development. Talk to her about functional programming, language design and implementation, and speech technology, and ask her about Mozilla, Outreachy, and the Recurse Center. She can usually be found in San Francisco—that is, when she’s not traveling the world trying to share the joy of programming and make the tech community more diverse and accessible.
©2017, O'Reilly Media, Inc. • (800) 889-8969 or (707) 827-7019 • Monday-Friday 7:30am-5pm PT • All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners. • firstname.lastname@example.org