Chapter 14
Constructing Functions from Functions
WHAT’S IN THIS CHAPTER?
- Function composition
- Partially applying algorithms
- Combining function construction techniques
Function construction is an important topic in functional programming. Functions are the only existing building blocks that make up application code in pure functional languages. They are reusable elements, comparable to classes in an object oriented language. Of course, to reuse an element, whether it’s a function or a class, it is necessary to be able to put pieces together to form a new creation. For this purpose, object oriented languages typically use inheritance, in all its various shapes.
In functional languages, there are two main techniques that can be used to create new functions from existing ones: partial application, which was discussed in Chapter 8, and composition, which is the topic for the next section. These techniques can also be combined, which allows programmers to maximize the reuse potential of existing functions.