Skip to content

Instantly share code, notes, and snippets.



Last active Mar 14, 2020
What would you like to do?
Pair samples
// combine different data types
val testName = "Kotlin Test"
val grade = 10
val resultTest = Pair (testName, grade)
// get the parts of Pair
val book = Pair("Learn Kotlin from GDE", 20)
val (title , price) = book
println("Title = ${book.first} , Price = ${book.second}")
// infix function
val yellowScarf = "yellow" to "scarf"
println(yellowScarf.first) // => yellow
println(yellowScarf.second) // => scarf
// nesting with parentheses
val clothes = ("yellow" to "scarf") to ("blue" to "blouse")
println(clothes.second.first) // => blue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment