Eduardo Guerra
09/11/2020, 1:47 PMfunc returnMultipleValues() -> (String, Int, Double) {
return ("Swift Tuple", 12, 3.14)
}
PS. I know how to use lists hahaha, I just think that it would be a lot easier this wayraulraja
09/11/2020, 2:32 PMhenrikhorbovyi
09/11/2020, 2:41 PMEduardo Guerra
09/11/2020, 2:43 PMdata class TwoThings(val id: String, val number: Int)
fun returnTwoThings(): TwoThings {
// Complex computation...
return TwoThings(strId, number)
}
But compared to the swift syntax it's really boilerplate, especially if I'm willing to use this combination only onceedrd
09/11/2020, 2:51 PMPair
and Triple
for that:
fun returnTwoThings(): Pair<String, Int> {
return strId to number
}
Which can then be extracted nicely with destructuring:
val (first, second) = returnTwoThings()
Eduardo Guerra
09/11/2020, 2:55 PMedrd
09/11/2020, 2:57 PMEduardo Guerra
09/11/2020, 3:04 PMkioba
09/11/2020, 5:24 PMIf you need more than 3 elements … there maybe a design problem in your code.I used to think the same, later I run into problems over and over where generating a new, short lived
data class
was bloating the codebase and implementing a generic TupleN solution was the resolution.
I believe there is space for tuples especially areas where we would use them as function arguments.Eduardo Guerra
09/11/2020, 5:48 PMkioba
09/11/2020, 6:02 PMNir
09/13/2020, 2:35 AMNir
09/13/2020, 2:35 AMNir
09/13/2020, 2:35 AMNir
09/13/2020, 2:35 AMNir
09/13/2020, 2:36 AMNir
09/13/2020, 2:37 AMalexsullivan114
09/16/2020, 7:00 PMNir
09/16/2020, 7:02 PMNir
09/16/2020, 7:02 PMNir
09/16/2020, 7:02 PMNir
09/16/2020, 7:02 PMalexsullivan114
09/16/2020, 7:02 PMNir
09/16/2020, 7:03 PMNir
09/16/2020, 7:03 PMalexsullivan114
09/16/2020, 7:03 PMNir
09/16/2020, 7:03 PMNir
09/16/2020, 7:04 PMNir
09/16/2020, 7:04 PMNir
09/16/2020, 7:05 PMzip
in python, no problem