I have the following code but it doesn't compile. I think the problem is that I need to tell it that T has to be a subclass of Event?
The type of scala.swing.Reactions.Reaction is PartialFunction[Event, Unit]
The error is: type mismatch; found : PartialFunction[T,Unit] required: scala.swing.Reactions.Reaction
import scala.swing.event.MousePressed
import scala.swing.Component
import scala.swing.Reactions
import reactive.EventSource
import reactive.EventStream
class TypeIssue {
type PartialAdapter[T] = (T => Unit) => PartialFunction[T, Unit]
def adMousePressed(c: Component)(f: MousePressed => Unit): PartialFunction[MousePressed, Unit] = {
case MousePressed(`c`, point, mods, clicks, triggersPopup) => f
}
def eventToStream[T](r: Reactions, ad: PartialAdapter[T]): EventStream[T] = {
val v = new EventSource[T] {}
r += ad(e => v.fire(e)) // error on this line
v
}
}
import-statements, likeimport scala.swing.event._It might be 5 more lines, but instead of 100 users, trying to find out, which import is necessary, ... - it's just such a waste of time.