Groovy web console

subscribe to the feed Subscribe
to this
site
for-loop-closure (via #groovywebconsole)
tweet this snippet Tweet
this
script

for-loop-closure

Published 6 months ago by Anonymous
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def templates = []
templates << 'TOMCAT'
templates << 'MEAN'

def steps = [:]

for (String template: templates) {
  // When the closure below is called, it references the `template` var
  // which has the last value of 'MEAN'
  steps[template] = { "Run template ${template}" }
}

for (String t: templates) {
  println("${t}: ${steps[t]()}")
}