|
This post originated from an RSS feed registered with Java Buzz
by Brian McCallister.
|
Original Post: Closure Recursion in Groovy
Feed Title: Waste of Time
Feed URL: http://kasparov.skife.org/blog/index.rss
Feed Description: A simple waste of time and weblog experiment
|
Latest Java Buzz Posts
Latest Java Buzz Posts by Brian McCallister
Latest Posts From Waste of Time
|
|
Wrote a fun little groovy script earlier today to copy IMAP messages to Exchange. JavaMail and Groovy made this pretty simple, so simple I had to do a bit of gold plating. Oh well =)
The fun part is in this snippet:
traverse = { folder, operation |
traverse_subfolders = { folder, operation |
recur = this
folder.list().each {
operation(it)
recur(it, operation)
}
}
operation(folder)
traverse_subfolders(folder, operation)
}
Groovy suffers from a cannot-call-closure-by-name-from-itself problem. Because the closure is a first class object though, you have access to it via this, so you can, in fact, recur on your closure.
Read: Closure Recursion in Groovy