Suppose I have the following class Foo, that supports a function of any arity using the tupling trick:
abstract class Foo[T, R] {
def pull: T => R
}
I can define a subclass with the following syntax:
implicit def function2Tofunction1[T1, T2, R](f: (T1, T2) => R): ((T1, T2)) => R = {
f.tupled
}
class Moo extends Foo[(Int, Int), Int] {
def pullImpl(x: Int, y:Int):Int = x + y
def pull = (pullImpl _) // implicit converts to tupled form
}
val m = new Moo()
m.pull(4, 5)
This is pretty clunky. The ideal syntax would be as follows:
class Moo extends Foo[(Int, Int), Int] {
def pullImpl(x: Int, y:Int):Int = x + y
}
Is there any way to define my base class such that this can be achieved?