This chapter is from the book
4.9 Zipping
One reason for using tuples is to bundle together values so that they can be processed together. This is commonly done with the zip method. For example, the code
val symbols = Array("<", "-", ">") val counts = Array(2, 10, 2) val pairs = symbols.zip(counts)
yields an array of pairs
Array(("<", 2), ("-", 10), (">", 2))
The pairs can then be processed together:
for (s, n) <- pairs do print(s * n) // Prints <<---------->>