Last active
December 26, 2015 18:19
-
-
Save hanbzu/7193925 to your computer and use it in GitHub Desktop.
Scala: pairs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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