8 Mar 2005 03:19
Re: what about sets?
See the source code - in particular groovy.lang.MetaClass which is where most of the MOP lives On 7 Mar 2005, at 14:34, Furash Gary wrote: > John, can you give me more information on what groovy does right NOW? > What is a "MOP"? > > > Gary Furash, MBA, PMP > Applications Manager, Maricopa County Attorney's Office > 602-506-0351 (Work), 602-725-1985 (Mobile) > > -----Original Message----- > From: John Rose [mailto:rose00@...] > Sent: Friday, March 04, 2005 5:22 PM > To: user@... > Subject: Re: [groovy-user] what about sets? > > On Mar 4, 2005, at 15:20, Furash Gary wrote: >> The last one with the long name is probably not appropriate (since >> it's not very java-ish and is more like a struct). It's something you > >> can do in VB, ABAP, or JudoScript. Essentially, you do this: >> >> x = new Thingy("Field1", "Field2"); > Thingy is some sort of generic row-set, I guess? > > Such things can be built in Groovy, since a Groovy object's field > schema > can be data-driven, not just class-driven as in Java. > (There''s a MOP that gives the right hooks.) > >> Then you can do cool stuff like: >> >> For (row in x) { >> row.Field1 = "potato"; >> row.Field2 = "a round starchy thing"; } >> >> Or >> sumValue = x.sum("Field5") > Often you don't need to string-quote the field name in Groovy. > This example might be better with the distributive *. operator: > sumValue = x*.Field5.sum() > > I'm cheating, there really isn't Collection.sum, yet, but it could be > spelled like this: > myList.inject(0){x,y|x+y} > > Maybe Groovy deserves more methods like sum. > I hope we have time at some point to go and systematically 'steal' from > the Common Lisp sequence functions and/or Smalltalk's collections API. > Those designs are quite powerful and mature. ("Best of breed".) > >> Or >> for (row in x.restrict("Field5", "v")) { >> println(row is now only rows with a "v" in field 5); >> } > Again, using the dot operator directly: > for (row in x.collect{it.Field5 == "v"}) ... > > Cheers. > > -- John > > James /********************************** * James Strachan * * Protique * http://protique.com/ * Enterprise Open Source * * Blog: * http://radio.weblogs.com/0112098/ **********************************/
)
>
>> Or
>> for (row in x.restrict("Field5", "v")) {
>> println(row is now only rows with a "v" in field 5);
>> }
> Again, using the dot operator directly:
> for (row in x.collect{it.Field5 == "v"}) ...
>
> Cheers.
>
> -- John
>
>
James
/**********************************
* James Strachan
*
* Protique
*
RSS Feed