user
06/25/2020, 9:23 AMdiesieben07
06/25/2020, 9:24 AMvaskir
06/25/2020, 9:28 AMdiesieben07
06/25/2020, 9:29 AMvaskir
06/25/2020, 9:52 AMcity
is decomposed to be passed somewhere I guess, so, the place where it's passed accepts city: String
, this is the problem. If it accepted city: City
, the code won't compile after Address
being decomposed to ..., city: PostalCode
.diesieben07
06/25/2020, 9:54 AMCity
then? Probably data class City(val name: String)
.
And:
val (name) = city
But now a city also needs a nickname:
data class City(val nickName: String, val name: String)
Tada, its broken againdiesieben07
06/25/2020, 9:54 AMvaskir
06/25/2020, 9:57 AMdiesieben07
06/25/2020, 9:57 AMvaskir
06/25/2020, 9:58 AMvaskir
06/25/2020, 9:59 AMdiesieben07
06/25/2020, 10:00 AMdata class Complex(val real: Double, val imag: Double)
val (imag, real) = someComplex
Will not do what you want. The omitting of values is not the problem.sindrenm
06/25/2020, 11:16 AMfun componentN
(where N
is the position of the field we're pulling out). Having such a system allows for setting up deconstruction logic ourselves. Of course, when the compiler deals with it for us (as is the case for data classes, for instance), then it doesn't matter, but those other cases are interesting.diesieben07
06/25/2020, 11:20 AMoperator fun componentName()
would destructure to name
. The compiler would generate that for data classes of coursediesieben07
06/25/2020, 11:21 AMval (name, age) = person
is sugar for val name = person.name; val age = person.age
pavi2410
06/25/2020, 8:29 PMdiesieben07
06/26/2020, 6:01 AM