The Artima Developer Community
Sponsored Link

Java Buzz Forum
Closure Recursion in Groovy

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Brian McCallister

Posts: 1282
Nickname: frums
Registered: Sep, 2003

Brian McCallister is JustaProgrammer who thinks too much.
Closure Recursion in Groovy Posted: Mar 25, 2004 9:39 AM
Reply to this message Reply

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

Advertisement

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

Topic: JNN: the Juicy News Network Previous Topic   Next Topic Topic: public class Foo implements Broken

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use