As the question says I am trying the following (does not compile):
object O {
def apply(i: Int): Boolean = i % 2 == 0
}
val f: Int => Boolean = O
So I tried this:
implicit def apply2Fct[A,B](applier: { def apply(a: A): B }) = {
new Function[A,B] { def apply(a: A): B = applier(a) }
}
But the compiler complains about “Parameter type in structural refinement may not refer to an abstract type defined outside that refinement”.
EDIT :
Due to the answer of Jean-Philippe Pellet I have to mention that I can´t let O extend Function[A,B] respectively Function[Int,Boolean].
In case you haven’t thought about it and the code is actually in your hands, you might also simply do:
Or, putting the structural type explicitly to f, one could say: