Created
June 16, 2011 17:11
-
-
Save krsmes/1029712 to your computer and use it in GitHub Desktop.
lazy evaluation of blocks in a groovy string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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