Skip to content

Instantly share code, notes, and snippets.

@krsmes
Created June 16, 2011 17:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krsmes/1029712 to your computer and use it in GitHub Desktop.
Save krsmes/1029712 to your computer and use it in GitHub Desktop.
lazy evaluation of blocks in a groovy string
def lazy = { {w->w<<it()}.asWritable() }
def x = "it is now ${System.currentTimeMillis()}"
def y = "it is now ${{it->it<<System.currentTimeMillis()}.asWritable()}"
def z = "it is now ${lazy{System.currentTimeMillis()}}"
// change to x,y,z - x prints the same number all 5 times
(1..5).each { println z; sleep 250 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment