mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
[Kotlin/en] Add more destructuring examples (#2419)
This commit is contained in:
parent
98bb8f8432
commit
7d00a22bde
@ -176,6 +176,17 @@ fun helloWorld(val name : String) {
|
||||
val (a, b, c) = fooCopy
|
||||
println("$a $b $c") // => 1 100 4
|
||||
|
||||
// destructuring in "for" loop
|
||||
for ((a, b, c) in listOf(fooData)) {
|
||||
println("$a $b $c") // => 1 100 4
|
||||
}
|
||||
|
||||
val mapData = mapOf("a" to 1, "b" to 2)
|
||||
// Map.Entry is destructurable as well
|
||||
for ((key, value) in mapData) {
|
||||
println("$key -> $value")
|
||||
}
|
||||
|
||||
// The "with" function is similar to the JavaScript "with" statement.
|
||||
data class MutableDataClassExample (var x: Int, var y: Int, var z: Int)
|
||||
val fooMutableDate = MutableDataClassExample(7, 4, 9)
|
||||
|
Loading…
Reference in New Issue
Block a user