Chapter 6. Processing values using higher-order functions
This chapter covers
- Working with tuples options and lists
- Writing higher-order functions for our types
- Using automatic generalization in F#
- Composing functions and partial application
In the previous chapter, we introduced the most common functional values. You’ve seen how these values can be constructed and how to work with them using pattern matching. Expressing all of the logic explicitly like this can be tedious, especially if the type has a complicated structure.
The types of values composed from one or several simpler values include tuples and options from the previous chapter, but also lists from chapter 3. In general, tuples are formed from values of several types. They contain exactly one value of each type. Options can contain zero or one value, and lists contain any finite number of elements. When working with these composed values, we often want to apply some operation to the underlying values. Doing so involves the recurring and boilerplate task of deconstructing the composed value into its components and reconstructing it after we apply the operation.
In this chapter, we’ll see how to process values in an easier way. We’ll do this by writing functions that abstract us from the underlying structure of the value and can be simply parameterized to perform a particular operation with some part of the value. We’ll see that this approach is more concise than using pattern matching explicitly.