Pure functions
The
@PureFunction annotation is used to mark methods as
pure.
A method is considered a pure function if:
- The method always returns the same outputs for the same inputs.
- The state at the start of the method call and the state at the end of the method call are the
same: they contain the same set of objects, assign the same value to each attribute, and assign the
same value to each variable.Two values are considered the same if:
v == wevaluates to true, wherevandware primitive values.v.equals(w)evaluates to true, wherevandware two objects and are neither arrays nor collections.- Two collections contain the same elements in the same order.
- Two arrays have the same size and contain the same elements in the same order.
When classes are imported to create the external library, the source code is reviewed to automatically detect pure functions. The result of this code review is stored in the resources/extannotations folder. However, complex pure functions may not be automatically detected and should be manually annotated. Pure functions can be declared in the source code, or in an external annotation file.
A method needs to be marked as a pure function to be called in the expression part of a rule, as explained in Method restrictions.