Transforming the class to become pure

As we discussed in Chapter 2, Manipulating Functions in Functional Programming, we have to create a pure function in functional programming to avoid the side effect. If we come back to the previous GetActiveCustomerByFunctionField() method definition, it iterates a registeredCustomers static member that is a global variable. It will be a problem since the GetActiveCustomerByFunctionField() method will feed a different output, although with the exact same passed as an argument.

To counter this problem, we have to abolish this global variable. We then have to modify the method definition as follows:

    template<typename T>    vector<T> Customer::GetActiveCustomerByFunctionField(      vector<Customer> customers,

Get Learning C++ Functional Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.