I'm new to scala and wanted to iterate over a list[list[(String, Double, Int)]] to print each inner list elements, do some calculation and then align the result of the calculation. I'm cal each item in the inner list.
For example:
Data:
val x: List[List[(String, Double, Int)]] = List(List(("Coke", 2.50, 1),("Pepsi", 2.50, 2)), List(("Red Wine", 4.50, 2), ("Beer", 3.00, 2)))
Using the below to print out:
for ((list, tableIdx) <- x.zipWithIndex) {
println("Table" + (tableIdx+1) + "order is:\n"
+ list.mkString("\n")
)
}
the output is:
Table1order is:
(Coke,2.5,1)
(Pepsi,2.5,2)
Table2order is:
(Red Wine,4.5,2)
(Beer,3.0,2)
Desired output:
Table 1 Order:
1 X Coke $2.50
2 X Pepsi $5.00
Subtotal = $7.50
Table 2 Order:
2 X Red Wine $9.00
2 X Beer $6.00
Subtotal = $15.00
Bill Total = $23.50
So my question is how to get the desired results please
Thanks