For a DSL I need to implicitly extend function values. For instance:
trait PimpedFunction[-A, +B] extends Function1[A, B] {
def foo = 42
}
object PimpedFunction {
implicit def pimp[A, B](f: Function1[A, B]): PimpedFunction[A, B] =
new PimpedFunction[A, B] {
def apply(a: A) = f(a)
}
}
A function that uses PimpedFunction
could be defined as something like:
def takes(f: PimpedFunction[String, Int]) = f.foo
The problem is on the code that calls takes
. The following works as expected:
takes((_: String).size)
But if I elide the parameter type the compile fails to infer it:
takes(_.size)
Can I change anything in order to help scalac's inference?
OBS: The real use case is related to this: https://gist.github.com/xeno-by/4542402