Groovy with spice – curried closures

Groovy rocks!

I have used Groovy swing builder before to layout some basic Swing UIs, but recently I used it for the first time for some real scripting. It was a script to do some database maintenance, and I was amazed at how easy, fun and productive Groovy can be.

What surprised me most was how easy it was to refactor as I went along. I had assumed that it will be inherently more difficult to modify it without static typing and full IDE support. Not the case at all, although it was a single script, and so things might be different if it is a Groovy program spread over multiple scripts.

Incidentally, the Codehaus Groovy Closures page has the easiest to understand explanation of what curried functions are –

You can fix the values for one or more arguments to a closure instance using the curry() method from the Closure type. In fact, this action is often referred to as currying in functional programming circles, and the result is generally referred to as a Curried Closure. Curried closures are very useful for creating generic closure definitions, and then creating several curried versions of the original with differing parameters bound to them.

I had glanced over curried functions in past, and it always looked like something that I will have to sit down and write some code to fully understand. But this explanation just clicked instantly. Thanks to whoever wrote this; I am sure I will find a use for it again soon.