During the first four chapters of this book, we discussed patterns and practices a lot. The strategy pattern is one of the important patterns of Gang of Four (GoF) patterns. This falls under the behavioral patterns category and is also known as a policy pattern. This is a pattern that is usually implemented with the help of classes. This is also an easier one to implement using functional programming.
Jump back to the Understanding functional programming section of this chapter and reconsider the paradigm of functional programming. Higher-order functions are one of the important paradigms of functional programming; using this, we can easily implement a strategy pattern in a functional way.
Higher-order functions (HOFs) are the functions that take parameters as functions. They can also return functions.
Consider the following code that...