I have the following problem. I tried to create a high-order function that takes two parameters: String and the type of the function. The type of function is defined as follows:
(String, List[String]) => List[(String, List[String])]
I also defined two functions f1 and f2 that are of the same type. Subsequently, I try to call myfun using f1 or f2 . Here is the code:
object Main extends App { def f1(t: (String,List[String])): List[(String,List[String])] = ... def f2(t: (String,List[String])): List[(String,List[String])] = ... def myfun(tableName: String)(fn: (String,List[String]) => List[(String,List[String])]): List[(String,List[String])] = ... val res: List[(String,List[String])] = myfun("...")(f1) res foreach println val res2: List[(String,List[String])] = myfun("...")(f2) res2 foreach println }
and here is the error:
[error] found : (String, List[String]) => List[(String, List[String])] [error] required: (String, List[String]) => List[(String, List[String])] [error] val res: List[(String,List[String])] = myfun("...")(f1)
I cannot understand why the compiler complains. Can someone explain this?
smikesh
source share