Refactoring the imperative class to become a functional class
Indeed, the preceding Customer
class can work well, and we have successfully invoked its methods. However, the class can still be tweaked by transforming it into a functional class. As we can see in the preceding code, we can implement a pure function, first-class function, higher-order function, and memoization to it to make it become functional. So, in this section, we will refactor the Customer
class to become a functional class and use the knowledge we have from the previous chapters. In the upcoming section, we will implement the functional method that we have discussed in the previous chapter, which is the first-class function.
Passing a function as a parameter
As we discussed in Chapter 2, Manipulating Functions in Functional Programming, we can rewrite the function to be a first-class function, which means we can pass a function to another function. We will simplify the definition of all the four methods we have in the Step01...