I am new to Kotlin and I wanted to return multiple values from a function.
I checked this post:
How do we return multiple values from a function in Kotlin like we do in swift? I am using a recursion function where I don't have to use var or val when getting return values.
My Code:
private fun folderSizeInBytes(directory: File): Pair<Long, Int> {
var length: Long = 0
var size : Int = 0
for (file in directory.listFiles().orEmpty()) {
if (file.isFile) {
length += file.length()
size++
}
else
(size,length) = folderSizeInBytes(file)
}
return Pair(length, size)
}
But at (size,length) = folderSizeInBytes(file)
there is an error, saying there is unexpected tokens. Is it possible to do this without recreating size and length or a Pair object?