I've run into a bit of a problem. I need to convert the types
Map[String, Iterator[Int]] -> Iterator[Map[String, Int]]
My current approach at solving this problem is by using a recursive function:
def Inverter(input: Map[String, Iterator[Int]], output: Iterator[Map[String, Int]]) = {
val inversion: Map[String, Int] = input.flatMap {case (symbol, iterator) => iterator.hasNext match {
case true => Some((symbol,iterator.next))
case false => None
}}
inversion.size match {
case 0 => output
case _ => Inverter(input, output ++ Iterator(inversion))
}
}
This code solves the problem, but is too slow. I think it has something to do with the ++ call being slow. Is there any way I can cons elements onto the head of an Iterator like I can a List in constant time? If not, can anyone come up with a good workaround?