Groovy web console

subscribe to the feed Subscribe
to this
Multiple assignment (via #groovywebconsole)
tweet this snippet Tweet

Multiple assignment

Published 1 year ago by piotrgajow with tags webappcraft
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def calculate(a, b) {
    def sum = a + b
    def diffAB = a - b
    def diffBA = b - a
    return [sum, diffAB, diffBA]

def (sum, diff1, diff2) = calculate(5, 3)

assert sum == 8
assert diff1 == 2
assert diff2 == -2