Groovy Tuple Varags

def calculate(String key, Integer... values) {
    // Method return a Tuple2 instance.
    new Tuple2(key, values.sum())
}
 
// Use multiple assignment to
// extract the values from the tuple.
// Tuple2 has typed objects.
def (String a, Integer b) = calculate('sum', 1, 2, 3)
 
assert a == 'sum'
assert b == 6
​

Comments

Popular posts from this blog

அவன் ஏன் கூலியானான்?

தட்டு வண்டியில் காளிக்கோயில் - சிறுகதை

Groovy Tuples