Friday, April 4, 2008

So enjoyable

While hacking GrailsCrowd today, I caught myself thinking that programming in Groovy is such an enjoyable experience (for me). Take this method for example:


// Social feature: gets a list of 'colleagues' working on the same projects as *this* member
def getProjectColleagues() {
getActiveProjects().collect
{it.participants}.flatten().findAll
{it.participant.id != this.id}.collect {it.participant}
}
Is it possible to navigate "deep" object graph and express the same intent with the similar compactness in 'raw' Java code? I think not :-)

Later...

4 comments:

Robert O'Connor said...

nice =)

Graeme Rocher said...
This comment has been removed by the author.
Graeme Rocher said...

Could be written as

activeProjects.participants*.flatten()
.findAll{it.participant.id != this.id}
.particpant

Letting Gpath do the magic ;-)

Dmitriy Kopylenko said...

Good point. Thanks for the tip, Graeme!