groovy - For loop variable initialisation from a list -


groovy allows unfolding lists in assignment, in:

(x, y) = [1, 2] 

so assumed similar work in loop, in:

list = [[1, 2], [2, 4], [3, 6]] ((elm1, elm2) in list) {...} 

which turns out syntax error. style not possible or there trick i'm missing?

i guess won't work for loop (or don't know syntax), two-argument closure can used iterate such list, unfold tuples:

def list = [[1, 2], [2, 4], [3, 6]] assert list.collect { a, b -> + b } == [3, 6, 9, ] 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -