[rules-users] Accumulate / collect

Esteban Aliverti esteban.aliverti at gmail.com
Wed Nov 16 04:34:57 EST 2011


You already have 2 accumulate functions to do what you need:

   - collectList
   - collectSet

So, your rule will look like this:
   $countries : HashSet(empty == false) from accumulate (City($name matches
"X.*", $country : country), collectSet($country))


Best Regards,

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Esteban Aliverti
- Developer @ http://www.plugtree.com
- Blog @ http://ilesteban.wordpress.com


2011/11/15 Wolfgang Laun <wolfgang.laun at gmail.com>

> This is possible with an accumulate where you code the init/action/result
> explicily. Perhaps not fully "out of the box" but a box that holds
> everything would be rather big, wouldn't it? ;-)
>
> -W
>
>  2011/11/15 Bruno Freudensprung <bruno.freudensprung at temis.com>
>
>>  **
>> 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.
>>
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20111116/6693bb45/attachment.html 


More information about the rules-users mailing list