multiple return syntax

groovy

Solution

If you are trying to use Groovy's multiple assignment, you can do something like this:

def func1 = {
    ['jeff', 'betsy', 'jake', 'zack']
}

def (dad, mom, son1, son2) = func1()

assert 'jeff' == dad
assert 'jake' == son1
assert 'zack' == son2
assert 'betsy' == mom

In your example you used square brackets instead of parens, which will not work.

Problem

I have a function that returns multiple values like this: ``` def func1() { return [val1, val2] } ``` How do I go about assigning these return values to another variable in the function that calls this function. I imagine it would be something like: ``` def funcThatCalledfunc1 { def [x,y] = func1() } ``` I want to end up `x` having value of `val1` and `y` having value of `val2`.

Original source