Up to Drools 5, the accumulate function API supports only a single argument to the function, but that argument can be an array or a list. So what I do on my own implementations is to pass the $param as one element of the array and $o as the other. It is not ideal, but it is how you can do that in Drools 5. In Drools 6 I will change the API to support multiple parameters, but I've been postponing that because when I do it, it will break existing implementations of the interface.

   Anyway, if you are using the MVEL dialect, creating a list is as simple as wrapping it in [ ], as you could see in my previous e-mail.

$options : List() from accumulate( 
      $op : Option(),
      matchAll( [ ${param}, $op ] ) )

    Edson

2011/1/29 groovenarula <gnarula1@la-z-boy.com>

Edson,

I did manage to use the 'CollectSetAccumulateFunction' as a template for the
MatchAll and have also successfully 'called' the accumulate function from a
rule written in a .drl file. But I'm stuck at one point - how to send the
value of $param to the accumulate method ? From what I understand, the
accumulate method is invoked for each fact - so if I write

    MatchAll( $o ) it will invoke the accumulate method and passing $o fact
to the method via the 'Object value' parameter.

So far so go, however, I'm stuck on how to pass the value of '$param' to the
accumulate method (or any other method like init, getResult for that
matter).

One option I can think of is to change the definition of the Option fact to
include a 'param' field and then write a rule that sets the value of that
field to $param (so every Options param field would get set to the value of
$param). I can then extract that in the accumulate method it self. But is
there a better way that I might be missing ?

Thanks in advance,
Gurvinder

--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2369936.html
Sent from the Drools - User mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list



--
  Edson Tirelli
  JBoss Drools Core Development
  JBoss by Red Hat @ www.jboss.com