I want to implicitly convert functions from A => Bto List[A] => List[B].
I wrote the following implicit definition:
implicit def lift[A, B](f: A => B): List[A] => List[B] = ...
Unfortunately, when I write the following code, implicit are not applied:
val plusOne: (List[Int]) => List[Int] = (x: Int) => (x + 1)
If I annotate a function with an explicit time, it works fine.
Why? How can i fix this?
UPDATE The problem seems to be related to anonymous functions. For comparison:
@Test
def localLiftingGenerics {
implicit def anyPairToList[X, Y](x: (X, Y)): List[X] => List[Y] = throw new UnsupportedOperationException
val v: List[String] => List[Int] = ("abc", 239)
}
@Test
def localLiftingFuns {
implicit def fun2ListFun[X, Y](f: X => Y): List[X] => List[Y] = throw new UnsupportedOperationException
val v: List[String] => List[Int] = ((x: String) => x.length)
}
The first is compiled. The second is marked as error
source
share