We discussed “composition” in the context of types—creating new types by combining other types. Now let’s talk about function composition, combining functions by connecting the output of the first to the input of the second.
For example, here are two functions. The first takes an apple as input and outputs a banana. The second takes a banana as input and outputs some cherries. The output of the first is the same type as the input of the second, and therefore we can compose them together like this:
After we have composed them together, we have a new function:
An important aspect of this kind of composition is information hiding. You ...