[rules-users] Accumulate / collect

Bruno Freudensprung bruno.freudensprung at temis.com
Tue Nov 15 12:32:39 EST 2011


Hi all,

There is something I can't express using "collect" or "accumulate" and I 
would like to have your opinion.
Let's imagine I have the following types :

     # a country type
*    declare Country
        name : String
     end
*
     # a city type holding a reference to its country
*    declare City
        name : String
        country : Country
     end
*
Let's imagine I have all Country and City objects into the working memory.
I want to get the set of Countries corresponding to Cities whose name 
starts with "X".

I have the impression that I need a kind of (nonexistent right?) 
"collect" syntax that would look like the "accumulate" syntax (a kind of 
"anonymous" accumulate function):

     # meaning I want to collect $country objects and not City objects
     $countries : HashSet() from collect (City($name matches "X.*", 
$country : country)*, $country*)

Or a home made accumulate function that builds a set of countries:

     # custom "buildset" accumulate function
     $countries : HashSet() from accumulate (City($name matches "X.*", 
$country : country), *buildset*($country))

Do you see any other (possibly out of the box) solution?

Many thanks in advance for your answers,
Best regards,

Bruno.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20111115/bfc58964/attachment.html 


More information about the rules-users mailing list