I am working through Ninety-Nine Scala Problems to learn more Scala. I am on P12 and coded the below solution for the problem.
def decode(l : List[Tuple2[Int,Symbol]]) : List[Symbol]
= l foldLeft(List[Symbol]()) { (symbols:List[Symbol], e:Tuple2[Int, Symbol]) => symbols ::: List(e._2) }
And I am getting the below compiler error.
error: type mismatch;
found : (List[Symbol], (Int, Symbol)) => List[Symbol]
required: Int
= l foldLeft(List[Symbol]()) { (symbols:List[Symbol], e:
Tuple2[Int, Symbol]) => symbols ::: List(e._2) }
What is causing the compiler error?
Scala version: Scala code runner version 2.10.0-M3 — Copyright 2002-2011, LAMP/EPFL.
It looks like it’s your use of the infix foldLeft call, you just need to change it to:
Note the “l.foldLeft” rather than “l foldLeft”, I suspect the compiler can’t quite determine what is a parameter to what.