I'm trying to pass high order generic function to another generic function as parameter. However, I am quite unable to make it work. Following is sample code of what I am trying to achieve.
def foo[T](data: Seq[T]) = {
//some codes
}
def bar[U](id: Sring, fn: Seq[U] => Unit) = {
criteria match {
case x => data:Seq[String] = //some data;
fn(data)
case b => data:Seq[Int] = //some data;
fn(data)
case c => data:Seq[Char] = //some data;
fn(data)
}
}
bar("123", foo)
If I run the code, I will get error - Type mismatch - expected Seq[U] found - Seq[String]