From 2 lists of the form List[(Int, String):
l1 = List((1,\"a\"),(3,\"b\"))
l2 = List((3,\"a\"),(4,\"c\"))
how can I combine t
Note that with this solution, the lists are traversed twice.
val l3 = (l1 zip l2).foldRight(List[(Int, String)]()) {
case ((firstPair @ (firstNumber, firstWord),
secondPair @ (secondNumber, secondWord)),
result) =>
if (firstWord == secondWord)
((firstNumber + secondNumber), firstWord) :: result
else
firstPair :: secondPair :: result
}