icon-cookie
The website uses cookies to optimize your user experience. Using this website grants us the permission to collect certain information essential to the provision of our services to you, but you may change the cookie settings within your browser any time you wish. Learn more
I agree
Summary | 12 Annotations
Anything can be on the right-hand side of a destructuring declaration, as long as the required number of component functions can be called on it.
2017/09/20 05:59
Note that the componentN() functions need to be marked with the operator keyword to allow using them in a destructuring declaration.
2017/09/20 06:00
Returning Two Values from a Function
2017/09/20 06:01
A compact way of doing this in Kotlin is to declare a data class and return its instance:
2017/09/20 06:01
Since data classes automatically declare componentN() functions, destructuring declarations work here
2017/09/20 06:01
So you can freely use destructuring declarations in for-loops with maps (as well as collections of data class instances etc).
2017/09/20 06:03
_
2017/09/20 06:04
The componentN() operator functions are not called for the components that are skipped in this way
2017/09/20 06:04
ter:
2017/09/20 06:06
Note the difference between declaring two parameters and declaring a destructuring pair instead of a parameter:
2017/09/20 06:06
a, b
2017/09/20 06:06
(a, b), c
2017/09/20 06:06