Tuples deprecated?

There's a more compact way to do multiple returns if you use the constructor of a class as the function:

// class constructor contains the logic, no need for a separate function. class only exists to act as a function class foo() {   val returnVal1 = ...   val returnVal2 = ... }

// use it
val f = foo()

I don’t think there’s a way to use this with multiple assignment, but you have the property names defined in the class so it doesn’t really matter.

Andrey mentioned this approach in a blog post or comment somewhere but I can’t find it.

1 Like