October 2018
Intermediate to advanced
370 pages
9h 15m
English
There are plenty of ways to retrieve values from Pair and Triple, but let's start with simple one. The value of a Pair can be retrieved by assigning it to the following variables:
val (name , price) = mobile
The name variable is assigned with Google and price contains 500 Euros, which is the price of a Google mobile. We can verify this by printing these variables like so:
println("Mobile = $name , Prince = $price Euro")
A Triple can be deconstructed in a similar fashion:
val (name, phone, address) = addressBookprintln("Name = $name , Phone = $phone , Address = $address")
There is another way to decompose the Pair and Triple classes. Each member of the Pair and Triple is assigned a name. The first element of the Pair ...
Read now
Unlock full access