A mental model is a clear picture of what a program is doing. It includes changing details such as variable state and function results, plus design qualities such as readability and expressiveness. Immutability and pure functions make this picture easier to build. section 3.4
From control flow to data flow
An imperative solution processes names through loops, conditionals, mutation, duplicate checks, and sorting. A functional rewrite expresses the same intent as a chain: filter valid values, map formatting, remove duplicates, sort, and evaluate. The chain makes each transformation and the movement of data visible without exposing every implementation detail. section 3.4
Listing 3.8. Demonstrating lazy function chains with Lodash
_.chain(persons) #1
.filter(isValid)
.map(_.property('address.country')) #2
.reduce(gatherStats, {})
.values()
.sortBy('count')
.reverse()
.first()
.value() #3
.name; //-> 'US'
Follow a Lodash chain as person records are filtered, mapped to countries, reduced into statistics, sorted, and transformed into one final value. section 3.4





