Let's consider the following function:
def printPfType[T](pf:PartialFunction[T, _])(implicit m:Manifest[T]) = {
println(m.toString)
}
Then I define the following test class:
case class Test(s:String, i:Int)
I can't write this:
printPfType {
case Test(_,i) => i
}
because the compiler can't infer the first parametric type of the PartialFunction. I have to specify it explicitly:
printPfType[Test] {
case Test(_,i) => i
}
But then the Test
type appears twice. Is there a technique to avoid this? How can I help the type inferer to avoid the duplicate?