Decomposition divides a complex task into smaller, manageable parts. In functional programming, those parts are functions: each handles one logical subtask, and their results can be joined into a complete solution. Splitting work this way makes the pieces easier to understand independently while preserving the larger goal. section 1.3
Start by identifying the jobs hidden inside one large operation. Keep splitting a job until its functions are simple and independent. A useful guide is the singularity principle: give each function one purpose. Pure functions and referential transparency support this design because connected functions need compatible inputs and outputs. section 1.3
Figure 1.3. The process of decomposing breaks showStudent into smaller parts. These subtasks are independent and simpler to understand, so that when combined, they help solve the bigger picture.
The diagram shows showStudent broken into independent subtasks that can be understood separately and then combined. section 1.3
Split display work into a pipeline
A student lookup can be expressed as separate steps: find a student, convert the result to CSV, and append it to the page. Composition connects those steps so that each function's output becomes the next function's input. This replaces one tangled operation with named units whose data flow is explicit. section 1.3
Decomposition also helps when a problem contains smaller versions of itself. Recursion solves that shape of problem by separating a base case, which returns a concrete answer, from a recursive case, which calls itself with smaller input. The smaller inputs must eventually reach the base case or the program will not terminate. section 3.5
Add an array recursively
To sum an array, return 0 for an empty array. Otherwise, add the first value to the sum of the remaining values. Each call reduces the array, and the results combine as calls return. The same pattern supports traversal of nested objects, XML or HTML, graphs, and trees when each level presents the same task. section 3.5
Small functions are not only an organizational choice. They can make code extensible and can enable memoization, which avoids repeating expensive evaluations. Decomposition therefore connects program structure to optimization, especially when recursive work is expressed in smaller self-similar parts. section 7.5









