diff options
author | Sergey Mashkov <cy6erGn0m@gmail.com> | 2016-10-05 17:59:16 +0300 |
---|---|---|
committer | ven <vendethiel@hotmail.fr> | 2016-10-05 16:59:16 +0200 |
commit | 7d00a22bded0b80f67e08fc807e857041f394ae5 (patch) | |
tree | ee6959b0d73e63681ed2a27b8981322481d6963d /kotlin.html.markdown | |
parent | 98bb8f8432e66c5721bb7cf7b808e750da9d499d (diff) |
[Kotlin/en] Add more destructuring examples (#2419)
Diffstat (limited to 'kotlin.html.markdown')
-rw-r--r-- | kotlin.html.markdown | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/kotlin.html.markdown b/kotlin.html.markdown index fe2811c5..d29b1471 100644 --- a/kotlin.html.markdown +++ b/kotlin.html.markdown @@ -175,6 +175,17 @@ fun helloWorld(val name : String) { // Objects can be destructured into multiple variables. 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) |