Drools functions

The short answer is: no.

This is because the facts need to be in the working memory.

What you can do, is to have a rule that takes all types of a certain class from the working memory, applies a function in the then section and inserts that new value in the working memory.

edit

This answer, originally posted on 2012, is not more relevant as newer versions of drools do support functions on the when clause.


Very likely an MVEL or an integration bug - function call adapters did not box/unbox primitive types. I see the question is quite old, but the problem has been since fixed (tested with 6.3.0-SNAPSHOT). For older versions, I'd try using boxed types : function boolean newFunction( Integer a ) ...


Along the lines of the selected answer above, after some experimentation I found that it is possible to create an external java method, whose class can be imported into the rules file, and wrapped in a MVEL function wrapper (Boolean) which can then can be called from the LHS as a parameter to an eval statement.

[External Java POJO_Class.myMethod]


import com.mypackage.POJO_Class;


function Boolean myFunctionName() {
   POJO_Class myClass = new POJO_Class();
   return myClass.myMethod(Parameters);
}



rule "Test Rule"
    when
      eval ( myFunctionName(parameters) )
    then
end