A couple things..
Regarding not being able to write constraints against what's returned from
accumulate functions like min and max - in one particular use case (mine for
example) this would not be a big deal. You are just trying to find the
min/max of a collection of objects that are comparable. Not being able to
do things like match based on intValue > someValue for the returned Number
the way it currently does certainly would be a problem in some cases.
I don't know enough yet about how drools does the object type pattern
matching - so sorry if this is a dumb question =) , but if the accumulate
functions just return something of type Object or Comparable, is there any
way to do the from pattern matching like you can right now? Could you
explicitly cast it somewhere?
The fact that you could do this (the min/max type functionality across any
comparable objects) with a custom accumulate function makes me think there
has got to be a generic way of doing it without writing custom accumulation
methods for each type... right?
Although, even though min and max would technically apply to Dates, things
like sum and average would not. So maybe we could have a couple generic
min/max accumulate methods for anything comparable (which would allow you to
get the min/max if you don't care about any of the details), then ones
specific to Number (what exists right now), and possibly some more if there
are other types that have commonly used accumulate actions.
In one particular use
Wolfgang Laun-2 wrote:
2011/3/25 Swindells, Thomas <TSwindells(a)nds.com>
> I thought from was effectively typeless (as it’s operating against a
List
> it can’t always know the type of the members anyway) and so it allows
any
> type on teh left – giving a runtime class cast exception if it can’t
do the
> conversion. Therefore if you know they type you are expecting you can
still
> use it on the LHS with whatever constraints you want?
>
Sure, "from" doesn't care what it produces, but accumulate
functions have to
return an object of some type. Currently. min and max return
java.lang.Double; therefore you can use java.lang.Number as a portmanteau
type. If min and max should include Data (and all other Comparable's), the
actual result type will have to be Comparable (or Object).
-W
>
>
> Thomas
>
>
>
> *From:* rules-users-bounces(a)lists.jboss.org [mailto:
> rules-users-bounces(a)lists.jboss.org] *On Behalf Of *Wolfgang Laun
> *Sent:* 25 March 2011 09:23
> *To:* Rules Users List
> *Subject:* Re: [rules-users] accumulate min over java.util.Date
>
>
>
> Now don't be hasty with a JIRA. Using Comparable for the arguments of
the
> min and max accumulate functions will give you a result that is --
> Comparable. So:
>
> $min: Comparable() from accumulate( Schedule( $d: date ), min( $d )
)
>
> OK, this will give you the minimum data, bound to $min, although it
won't
> let you write any constraint for the "Comparable" result
fact. But, what's
> worse, it will not let you write
>
> $min: Number( intValue > 100 ) from accumulate( X( $y: y ), min(
$y ) )
>
> any more (unless I'm very much mistaken).
>
> -W
>
>
> On 25 March 2011 03:56, Greg Barton <greg_barton(a)yahoo.com>
wrote:
>
> Well, if it can work that way it should. I'd say open a JIRA and
request
> that feature. It works with the "principle of least
confusion." :)
>
>
> --- On Thu, 3/24/11, jkrupka <jkrupka(a)gmail.com> wrote:
>
> > From: jkrupka <jkrupka(a)gmail.com>
>
> > Subject: Re: [rules-users] accumulate min over java.util.Date
>
> > To: rules-users(a)lists.jboss.org
>
> > Date: Thursday, March 24, 2011, 8:26 PM
>
> > Yea the docs weren't really clear
> > about it, so I just thought it would work
> > for anything that implemented Comparable =)
> >
> > Yep, used the long from getTime() - not the prettiest way
> > of doing it, but
> > it works great.
> >
> > Thanks!
> >
> > --
> > View this message in context:
>
http://drools-java-rules-engine.46999.n3.nabble.com/accumulate-min-over-j...
> > Sent from the Drools - User mailing list archive at
> >
Nabble.com.
> > _______________________________________________
> > rules-users mailing list
> > rules-users(a)lists.jboss.org
> >
https://lists.jboss.org/mailman/listinfo/rules-users
> >
>
>
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
> ------------------------------
>
>
>
**************************************************************************************
> This message is confidential and intended only for the addressee. If
you
> have received this message in error, please immediately notify the
> postmaster(a)nds.com and delete it from your system as well as any
copies.
> The content of e-mails as well as traffic data may be monitored by
NDS for
> employment and security purposes. To protect the environment please
do not
> print this e-mail unless necessary.
>
> NDS Limited. Registered Office: One London Road, Staines, Middlesex,
TW18
> 4EX, United Kingdom. A company registered in England and Wales.
Registered
> no. 3080780. VAT no. GB 603 8808 40-00
>
>
**************************************************************************************
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
>
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users