[rules-dev] DRL sorting (Bind to eval result?)

Wolfgang Laun wolfgang.laun at gmail.com
Tue Nov 29 09:03:13 EST 2011


A recent post was asking for options to do a sort in a DRL query.
(More generally, you could ask for any transformation of a
collection.) Below is what I finally managed to get to work, with
   Collection sortByKey(List x)
doing the actual sort, no matter how.

   query "sortedItems"
      $facts: List() from collect ( Fact() )
      $values: Collection() from collect ( Fact() from sortByKey( $facts ) )
   end

What looks clumsy to me is the 2nd pattern where you must unravel the
sorted collection so that you can collect it into the same thing,
which can then be bound to $values.

This is what one would like to have - but I think this is too rarely
required to warrant an additional operator.

   query "sortedItems"
      $facts: List() from collect ( Fact() )
      $values: Collection() <missing operator> sortByKey( $facts )
   end

-W


More information about the rules-dev mailing list