Abhinav
Abhinav

Reputation: 35

Scala: type mismatch found in mapping

Error: type mismatch; found : List[List[(Char, Int)]] required: List[(Char, Int)] at q<- x

a2 reduceLeft ((x,y)=>  
  for{  
    q<- x  
    b<- y  
  } yield (q::b::Nil)  
) 

where, a2 : List[List[(Char, Int)]].

If a2 is List[List[(Char, Int)]], x is List[(Char, Int)], so q is (Char, Int), and so is b, how it found List[List[(Char, Int)]]?

Upvotes: 0

Views: 230

Answers (1)

Jean Logeart
Jean Logeart

Reputation: 53819

The problem is that yield returns a List[(Char, Int)] so the for loop returns a List[List[(Char, Int)]].

Therefore, the reduceLeft complains since it expects the return type to be List[(Char, Int)].

Upvotes: 1

Related Questions