I am trying to combine lists with the following functions:
def merge(first: List[(Char, Int)], other: List[(Char, Int)]): List[List[(Char, Int)]] =
first.flatMap(tpl => other map (tpl2 => List(tpl, tpl2)))
def combine(l: List[List[(Char, Int)]]): List[List[(Char, Int)]] = l reduceLeft merge
Unfortunately, I get the following compiler message:
Error: type mismatch;
found: (List[(Char, Int)], List[(Char, Int)]) => List[List[(Char, Int)]]
required: (List[Product with java.io.Serializable], List[(Char, Int)]) => List[Product with java.io.Serializable]
l reduceLeft merge
I understand that reducing a List[Int] can only generate a result of Int. In my case, I have List[List[(Char, Int)]] so I expect that I can generate a result of List[(Char, Int)]. Can anybody help me understand what is wrong with my code?
tplto all elements of theotherlist of tuples? - Yuval Itzchakov