Skip to content

Instantly share code, notes, and snippets.

@magdamiu
Last active March 14, 2020 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magdamiu/a3cbbd009961e310a27f3f42055a3201 to your computer and use it in GitHub Desktop.
Save magdamiu/a3cbbd009961e310a27f3f42055a3201 to your computer and use it in GitHub Desktop.
Pair samples
// combine different data types
val testName = "Kotlin Test"
val grade = 10
val resultTest = Pair (testName, grade)
println(resultTest)
// 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