liveBook · Manning

Chapter 13: Chaining functional tools

What you will learn in chapter 13 of Grokking Simplicity

The introduction explains why complex array computations can be expressed as chains of simple functional-tool steps.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction explains why complex array computations can be expressed as chains of simple functional-tool steps.

Key terms: functional tools, chain, step

13.1 The customer communications team continues

The section builds a chain to find each best customer’s biggest purchase, then replaces a nested reduce() with the clearer maxKey() abstraction.

Key terms: chaining, filter(), map(), reduce(), maxKey(), callback, max(), identity function

13.2 Clarifying chains, method 1: Name the steps

The section shows how naming each step of a functional chain improves readability while leaving questions about reuse unresolved.

Key terms: chains, higher-order function, callbacks, inline functions, call graph

13.3 Clarifying chains, method 2: Naming the callbacks

This section shows how naming callbacks clarifies a chain and creates reusable functions that operate on individual values.

Key terms: callbacks, chains, call graph, filter()

13.4 Clarifying chains: Two methods compared

Compares two ways to clarify chains of functional tools and explains how to choose between them.

Key terms: naming steps, naming callbacks, higher-order functions, inline

13.5 Example: Emails of customers who have made one purchase

The section uses a filter–map chain to select customer emails, then shows how to combine chained operations when intermediate arrays become a performance concern.

Key terms: filter(), map(), chain of functional tools, stream fusion, reduce(), intermediate arrays, garbage-collected, bottleneck

13.6 Refactoring existing for loops to functional tools

The section presents two ways to refactor existing for loops into chains of functional tools and shows how loop structure can suggest map() and reduce().

Key terms: Understand and rewrite, Refactor from clues, chains of functional tools, map(), reduce(), outer loop, inner loop

13.7 Tip 1: Make data

This section shows how to make values implicit in a loop into an array so functional tools can operate on them.

Key terms: make data, intermediate arrays, slice(), functional tools

13.8 Tip 2: Operate on whole array at once

The section shows how turning a loop’s input into a subarray enables a whole-array operation, while explaining why a remaining loop cannot yet be replaced directly with map().

Key terms: subarray, reduce(), average(), whole arrays, map(), callback, current element, index i

13.9 Tip 3: Take many small steps

Shows how adding an intermediate array of indices lets a loop that creates subarrays be refactored into a map() call.

Key terms: indices, windows, map(), many small steps

13.10 Tip 3: Take many small steps

The section finishes a for-loop refactoring by separating two jobs inside a map callback and extracting the index-generating loop into a helper.

Key terms: map(), subarray, averaging, helper function, chain of functional tools

13.11 Comparing functional to imperative code

The section compares an imperative moving-average implementation with a functional version whose steps closely match the algorithm description.

Key terms: moving average, window, range(), functional tools

13.12 Summary of chaining tips

Summarizes practical ways to refactor for loops into chains of functional tools.

Key terms: Make data, array of data, Operate on the whole array, map(), filter(), reduce(), Many small steps, Replace conditionals with filter(), Extract helper functions, functional tools

13.13 Debugging tips for chaining

The section gives three ways to debug chains of functional tools: use meaningful names, inspect intermediate results, and trace the types flowing through the chain.

Key terms: Keep it concrete, pipeline, Print it out, print statement, chain, Flow your types, map(), filter(), reduce(), callback

13.14 Many other functional tools

The section introduces functional tools beyond map(), filter(), and reduce(), then shows how JavaScript and Java make such tools available and convenient.

Key terms: pluck(), concat(), frequenciesBy(), groupBy(), functional tools, standard libraries, array methods, method chaining, inline functions, index

13.15 reduce() for building values

This section uses reduce() to rebuild a shopping cart from a log of added items and shows why retaining that log is useful.

Key terms: reduce(), initial value, shopping cart, log, undo, event sourcing

13.16 Getting creative with data representation

The section shows how adding information to data can support later steps in a chain of functional tools, then applies the idea to building a softball roster.

Key terms: augmenting the data, operation as a piece of data, chain of functional tools, recommendation record, recommendPosition(), scorePlayer(), sortBy(), reverse(), roster

13.17 Line up those dots

This section uses the visual alignment of chained functional tools to show how data flows through a pipeline.

Key terms: functional tool chaining, vertical dots, pipeline

13.18 Conclusion

The conclusion presents chains of functional tools as step-by-step data transformations and connects them to a functional programming mind-set.

Key terms: functional tools, chains, data transformation

13.19 Summary

13.20 Up next…

The section transitions from tools for sequences to the upcoming challenge of working with nested data.

Where this is used later

Concepts explained in this chapter

← Chapter 12: Functional iteration Chapter 14: Functional tools for nested data →

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.