Implementing Macro
This change implements a new functional interface, called 'Macro' and adds functionality to add operations implementing this interface. Such an operation can be added using a symbolic name and calling the new
JsonLogic#addMacro(String name, Macro macro)
method. (addOperation() cannot be overloaded, because the signatures collide.).
The macros are free to
- access the arguments as nodes,
- evaluate any argument, any number of times, including no evaluation at all, in any order
- query the number of the argument.
The unit test adds an operation that has a side effect, and then also adds the macro "unless" that executes the second argument unless the first one is truthy. Since the test's second argument operates with a side effect (setting a boolean to true), the test can check that the argument was called when the first argument to unless was false and was not called in the second case.