Chapter 6. Composing functions

 

This chapter covers

  • Using functions for program clarity
  • The problem with state
  • Using functions to create abstractions
  • Techniques for combining functions

In contrast to what you learned about objects, you needn’t learn any more features to compose programs with functions. Instead, you must learn how to create your own features by putting together functions using the basic function glue that you learned in chapter 3. This principle applies to trivial examples such as defining an average function in terms of sum and divide functions and to nontrivial examples that you’ll see in this chapter. To compose programs with functions, you must learn principles and techniques, not features.

Functions have inputs (arguments) and outputs (return values). In that sense, they’re like pipes. You need to know not only the different ways of connecting those pipes but also the principles and techniques you need to do so effectively.

6.1. Clarity

6.2. State and mutability

6.3. Abstraction

6.4. Combinators

6.5. Summary