I have a problem with a generic class that I create in Scala. I have the following class:
class Channel[T, U](val endPoint : EventSource[U], val filter : Occurrence[T] => Boolean, val map : Occurrence[T] => Occurrence[U]) { def send(occurrence : Occurrence[T]) { if (filter(occurrence)) { endPoint.occur(map(occurrence)) } } }
Here, the channel [T, U] can be considered as a way of distributing Occurrence [T] from EventSource [T] to EventSource [U]. An entry is sent only if the filter function is true, and if this event is transmitted to the card, and the result is sent.
This class seems to be compiling and working correctly. My problem is that I want to connect several channels to an instance of EventSource [T] so that it can distribute Occurrences to several different EventSources of different types. My confusion is basically how to do this:
class EventSource[T] { var List[Channel[T,U]] list = ... }
What is here? T simply refers from type T to the EventSource to which list
belongs (is a member).
Sorry if this is vague or confusing!
EDIT: I should have noticed that I also want to add this list to the list:
list = list ++ List[Channel[T, U](new Channel[T, U](endPoint, filter, map))
Is adding a real problem?
source share