Hi, I found that if I add a static iterator() method to a class:
MyClass.class.metaClass.static[iterator] = { calculateTheIterator() } I can use MyClass.each/grep and all these wonderful groovy methods. This is for an EMF data model, where users often want to know stuff about objects of a certain type in their model. Now, obviously calculateTheIterator() needs some magic. What I currently do is I wrap things into a closure: withContext(context) { SomeClass.each { ... } SomeOtherClass.grep { } } the withContext method writes the context into a global static field somewhere, and the calculateTheIterator() method just reads that value and uses it to calculate the result using domain-specific knowledge. I wonder if there is a way to avoid that global static variable. Another question I have is, that I currently add the static iterator to ALL classes of my domain separately: for (Class c : allTheClasses) { c.metaClass.static[iterator] = { calculateTheIterator () } } Is there a better way to do this? Thanks, Felix -- Linux. The choice of a GNU generation.