I'm new to Scala, I'm stuck on this problem unfortunately.
I have a function type defined in Types.Subscribe that I want to reuse as follows:
object Types {
type Subscribe[T] = (T => T)
}
trait Adapter[T] {
def subscribe: Types.Subscribe[T]
}
class IntAdapter extends Adapter[Int] {
def map(subscribe: Types.Subscribe[Int]) = { 1 }
def subscribe(value: Int): Int = { 2 }
}
However, I get the following error from IntelliJ:
Class FooAdapter must either be declared abstract or implement abstract member 'subscribe: Types.Subscribe[T]'
It seems that def subscribe(value: Int): Int does not match function type (Int => Int), which is a bit confusing. If that's the case, how can I define a Subscribe function type that I would be able to reuse as described above?
I tried defining the function type using the apply method:
trait StreamSubscribe[T] {
def apply(value: T): T
}
However, I could not get this to work either.
I want to have a single source of truth for the type signature of the subscribe method, instead of repeating it in random places. How can I achieve that?
Adapterhasdef subscribeand yourIntAdapterhasdef subscribe(value: Int). Notice any difference?