Destructuring Tuples
Pull values back out.
Getting Values Out
Creating a tuple is only half the story. To use the values inside, you need to take them back out.
Scala gives you two main ways: numbered accessors and pattern destructuring. This lesson covers both.
Accessing by Position
Every tuple element has a position you can read with ._1, ._2, and so on.
Note that positions start at one, not zero. So ._1 is the first element.
val person = ("Alice", 30)
println(person._1)
println(person._2)All lessons in this course
- Creating Tuples
- Destructuring Tuples
- Building Ranges
- Ranges in Loops