Is it true than in Kotlin a function cannot return multiple values?!?!?
n
nanodeath
08/08/2020, 7:09 PM
multiple values means you aren't really using the type system nicely. in a pinch you can use Pair or Triple, but usually you want a data class. all are easy to destructure.
d
Daniele B
08/08/2020, 7:10 PM
in Go and Swift, you can return multiple values, and it’s really useful
r
Ruckus
08/08/2020, 8:45 PM
Actually not quite. In Go and Swift (as well as many other languages like TypeScript, Rust, Python, etc.), you can return a tuple, which is kind of like an anonymous container that holds arbitrary other values. You're still only returning a single value, but they add some nice syntax sugar that makes it easy and smooth.
Kotlin does not support tuples, so your best bet is to do as @nanodeath suggested.