|
|
|
|
|
by TeMPOraL
1997 days ago
|
|
Tangential: Pure impl v2: class foo {
public:
//enum is a keyword, so let's call it _enum
const _enum current_operator;
foo(_enum co) : current_operator(co) { }
// ... evalOp() as in your stateful impl example ...
};
//Example use:
Reduce(foo{ADD}, 1, 2, 3, 4, 5, 6);
Point being, functional purity doesn't necessarily mean only functions taking all their inputs as arguments. It means no mutable state. In the above example, the class foo essentially represents a partially applied evalOp(). If you have multiple, related functions working on similar sets of parameters, you could put them in such a class with const members to create what is essentially a package of partially applied functions. |
|