A pattern is a solution that can be applied to solve a variety of problems. The patterns we’ll discuss in this chapter are simply functions: functions that are so ubiquitous when coding functionally that they can be seen as the core functions of FP.
You’re probably familiar with some of these functions like Where and Select (which is equivalent to Map), having used them with IEnumerable. But you’ll see that the same operations can be applied to other structures, hence establishing a pattern. I’ll illustrate this with Option in this chapter; other structures will follow in coming chapters.
As usual, I suggest you type along in the REPL and see how these core functions can be used. (You’ll need to import the LaYumba.Functional library as shown in the sidebar “Using the LaYumba.Functional library in the REPL” in chapter 5.)
The first core function we’ll look at is Map. It takes a structure and a function and applies the function to the inner value(s) of the structure.1 Let’s start with the familiar case in which the structure in question is an IEnumerable.