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++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -