Skip to content

Instantly share code, notes, and snippets.

@hanbzu
Last active December 26, 2015 18:19
Show Gist options
  • Save hanbzu/7193925 to your computer and use it in GitHub Desktop.
Save hanbzu/7193925 to your computer and use it in GitHub Desktop.
Scala: pairs
// Pairs can be constructed easily using parentheses:
val pair: (Char, Int) = ('c', 1)
// In order to access the two elements of a pair, you can use the accessors `_1` and `_2`:
val theChar = pair._1
val theInt = pair._2
// Another way to deconstruct a pair is using pattern matching:
pair match {
case (theChar, theInt) =>
println("character is: " + theChar)
println("integer is : " + theInt)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment