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

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -