I'm attempting to extend the Function class with an implicit parameter, but I've not managed to appease the compiler. This is the code that I want to work:
class MyFun extends ((Int, Int) => Int) {
def apply(a:Int)(implicit b:Int):Int = a + b
}
And it doesn't compile:
[error] MyFun.scala:21: class MyFun needs to be abstract, since method apply in trait Function2 of type (v1: Int, v2: Int)Int is not defined
[error] class MyFun extends ((Int, Int) => Int) {
[error] ^
I've tried a few variants without success:
class MyFun extends ((Int, implicit Int) => Int) {
def apply(a:Int)(implicit b:Int):Int = a + b
}
[error] MyFun.scala:21: identifier expected but 'implicit' found.
[error] class MyFun extends ((Int, implicit Int) => Int) {
[error] ^
[error] MyFun.scala:40: ')' expected but eof found.
class MyFun extends ((Int)(implicit Int) => Int) {
def apply(a:Int)(implicit b:Int):Int = a + b
}
[error] MyFun.scala:21: ')' expected but '(' found.
[error] class MyFun extends ((Int)(implicit Int) => Int) {
[error] ^
[error] MyFun.scala:21: ';' expected but '=>' found.
[error] class MyFun extends ((Int)(implicit Int) => Int) {
[error] ^
Does anyone know how to do this?
Thanks,
Joe