From 7d00a22bded0b80f67e08fc807e857041f394ae5 Mon Sep 17 00:00:00 2001 From: Sergey Mashkov Date: Wed, 5 Oct 2016 17:59:16 +0300 Subject: [Kotlin/en] Add more destructuring examples (#2419) --- kotlin.html.markdown | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'kotlin.html.markdown') 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) -- cgit v1.2.3