val list = List((5,4), (3,2), (1,0))
list.map { case (a, b) => a * b }
Combine list of tuples into a single list using map
-
17-06-2023 - |
Question
Imagine that we have a list of tuples such as:
List((5,4), (3,2), (1,0))
How would you multiply the values in each tuple with themselves then combine the products into a single list?
List(20, 6, 1)
I believe there is a way to do so using Scala's built-in map function, but I'm unsure of how to do so.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow