liveBook · Manning

Chapter 14: Functional tools for nested data

What you will learn in chapter 14 of Grokking Simplicity

The introduction explains why higher-order tools for object values make immutable updates to deeply nested data less awkward.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction explains why higher-order tools for object values make immutable updates to deeply nested data less awkward.

Key terms: higher-order functions, objects as hash maps, deeply nested maps, immutable

14.1 Higher-order functions for values in objects

The team identifies duplicated updates to values inside item objects as a reason to seek a higher-order function for object data, rather than just arrays.

Key terms: higher-order functions, values stored in objects, duplication

14.2 Making the field name explicit

The section shows how making a field name an explicit argument removes duplication, then identifies a similar code smell in functions named for their operations.

Key terms: implicit argument in function name, express implicit argument refactoring, field name, operation

14.3 Deriving update()

This section derives update() by replacing several field-specific object operations with one higher-order, copy-on-write function.

Key terms: update(), higher-order function, callback, express implicit argument, replace body with callback, copy-on-write, objectSet()

14.4 Using update() to modify values

Shows how update() applies a value-level function to an object field without mutating the original object.

Key terms: update(), raise10Percent(), salary key, hash map, copy-on-write, calculation, action, modified copy

14.5 Refactoring: Replace get, modify, set with update()

Shows how to replace a get–modify–set sequence on one object key with a single update() call.

Key terms: get, modify, set, update(), copy-on-write, callback

14.6 Functional tool: update()

Introduces update() as a functional tool for changing one value under a key in an object.

Key terms: update(), object, key, calculation, current value

14.7 Visualizing values in objects

This section visualizes how update() changes a value in an object and points out why a nested-object update does not directly match the same pattern.

Key terms: update(), modify(), key, modified copy, get, get, modify, set, set

14.8 Visualizing nested updates

This section breaks a nested object update into five steps: two reads, a new value, and two modified copies.

Key terms: nested options object, value, key, modified copy

14.9 Applying update() to nested data

The section shows how applying the get–modify–set refactoring twice produces nested update() calls for nested objects.

Key terms: get, modify, set, update(), callback, nested objects

14.10 Deriving updateOption()

The section shows how to generalize a nested update by making the option name and modification function explicit arguments.

Key terms: implicit argument, explicit argument, option, modify argument, update(), nested data, nested updates

14.11 Deriving update2()

The section derives update2() by making an implicit argument explicit, yielding a tool for updating values two levels deep in nested objects.

Key terms: update2(), two keys, get, get, modify, set, set, express implicit argument refactoring, implicit argument, explicit argument

14.12 Visualizing update2() on nested objects

The section uses an item’s size option to show how a path locates a value nested inside objects.

Key terms: path, key, nested objects

14.13 Writing incrementSizeByName() four ways

The section presents four ways to increment a named cart item's size option through three levels of nested data.

Key terms: incrementSizeByName(), update(), update2(), incrementSize(), gets, modifies, and sets

14.14 Deriving update3()

The section derives update3() by making an implicit argument explicit and nesting update2() inside update() to reach four levels of data.

Key terms: update3(), update2(), update(), express implicit argument

14.15 Deriving nestedUpdate()

This section derives nestedUpdate() by replacing depth-specific update functions with a recursive function that follows a path of keys.

Key terms: implicit argument in function name, express implicit argument, path of keys, nestedUpdate(), update(), modify(), base case, recursive call, recursion, function call stack

14.16 The anatomy of safe recursion

This section explains the three conditions that keep recursion from running forever: a base case, a recursive case, and progress toward the base case.

Key terms: base case, recursive case, progress toward the base case

14.17 Visualizing nestedUpdate()

Introduces a planned visual walkthrough of a three-level nestedUpdate() call that increments a cart item’s size.

14.18 The superpower of recursion

The section explains why updating nested data calls for recursion rather than the straightforward traversal used for arrays.

Key terms: recursion, call stack, nested data, copy-on-write sets

14.19 Design considerations with deep nesting

The section explains why long nested-update paths are hard to understand and introduces abstraction barriers as a way to hide the intermediate data structures.

Key terms: nestedUpdate(), path, intermediate object, abstraction barrier, layer of functions, implementation

14.20 Abstraction barriers on deeply nested data

The section shows how named abstraction barriers make deeply nested data easier to work with by hiding structural details.

Key terms: abstraction barriers, deeply nested data, meaningful names, cognitive load

14.21 A summary of our use of higher-order functions

The section summarizes how higher-order functions support array processing, nested updates, copy-on-write operations, and error logging.

Key terms: higher-order functions, forEach(), map(), filter(), reduce(), update(), nestedUpdate(), copy-on-write discipline, withArrayCopy(), withObjectCopy()

14.22 Conclusion

The conclusion connects earlier functional-tool refactorings to nested data and identifies recursion as the way to handle arbitrary nesting depth.

Key terms: refactorings, nested data, recursion, functional tools

14.23 Summary

14.24 Up next…

Previews the application of first-class values and higher-order functions to challenges in distributed systems.

Concepts explained in this chapter

← Chapter 13: Chaining functional tools Chapter 15: Isolating timelines →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.