Here is a writable closure for some KML:
def kmlDocument = new groovy.xml.StreamingMarkupBuilder().bind{
mkp.xmlDeclaration()
mkp.declareNamespace('': 'http://www.opengis.net/kml/2.2')
kml{
Document{
Folder{
name('*** stations')
description('http://some.place.on.teh.webs/qry')
open('1')
stationTypes.each({type ->
Folder{
name(type[0])
description('Station Type: ' + type[0])
type[1].each({platform ->
Folder{
name(platform)
description('Platform: ' + platform)
stations[type[0] + platform].each({station ->
Placemark{
name(station.name)
description('http://some.place.on.teh.webs/qry/station?idtypeabbr=stnid&idvalue=' + station.stnidnum)
styleUrl(station.getIcon())
Point{
coordinates(station.coord)
}
}})}})}})}}}} //lameness filter ate my whitespace; doesn't look like LISP in real life
def f = new File('doc.kml')
f.delete()
f << kmlDocument
The cool thing is that I get all this plus seamless Java integration (i.e. every class in the standard library -- GregorianCalendar, for instance), all my Java tools work, and I can replace lots and lots of boilerplate Java code with one and two liners of Groovy. So:
ArrayList<String> list = new ArrayList<String>();
list.add("Blah");
list.add("Blah");
list.add("Blah");
list.add("Blah");
System.out.println(list);
Becomes:
def list = ["Blah","Blah","Blah","Blah"]
println list
And hey, with closures, if you want to do something like capitalize the first character of each string in that list it's really easy:
println list.collect({
it[0].toUpperCase() + it[1..it.length() - 1] //there's a better way to do this; I'm being pedantic
})
Which is not to say that Python couldn't do all that, but Groovy makes life for Java monkeys much easier.