Groovy web console

subscribe to the feed Subscribe
to this
site

msg

Published 1 month ago by ms
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
def ingest(val) {     println(val) }  

Map<String,Closure> map = [:]

int LEVEL = 4;

for(i in (0..<LEVEL) ) {
    int j = i; //bind i in this iteration
     map[j] = { ingest(j) }
}

map[0]()
map[1]()
map[2]()
map[3]()