ObservableBuffer.Change is the superclass of various case classes used to process changes to observable buffers. In order to match against case classes, and retain implicit type inference, adding a type parameter to Change appears to be necessary. As it stands right now, one needs to explicitly the parameter types of an arbitrary case class when applying a matcher in order for the compiler to assume the correct typing for that parameter or case class. Take this for instance:
changes.foreach {
case Add(_, elements) => // do your stuff
}
elements will be assumed to be of the type Traversable[Any] by the compiler, even if the collection being observed is of type X, in which case it should be Traversable[X]. In order to get the expected behavior from the compiler, we must say that we specifically want Traversable[X] (note that this will also generate an annoying erasure warning):
changes.foreach {
case Add(_, elements: Traversable[X]) => // do your stuff
}
and we cannot do
changes.foreach {
case Add[X](_ elements) => // do your stuff
}
as that is actually invalid syntax.
If Change were to have a type parameter T, one could specify the type of Changes when adding a ChangeListener to a buffer:
onChange { (collection: ObservableBuffer[X], changes: Seq[Change[X]]) =>
changes.foreach {
case Add(_, elements) => // do your stuff with Traversable[X]
}
}
As it stands right now, this would require is modifying the class signatures for operations to accept a type, and in the case of operation cases where type is unimportant (such as Reorder), the type Any may be specified when inheriting Change, or can be specified and implicitly inferred.
ObservableBuffer.Changeis the superclass of various case classes used to process changes to observable buffers. In order to match against case classes, and retain implicit type inference, adding a type parameter toChangeappears to be necessary. As it stands right now, one needs to explicitly the parameter types of an arbitrary case class when applying a matcher in order for the compiler to assume the correct typing for that parameter or case class. Take this for instance:changes.foreach { case Add(_, elements) => // do your stuff }elementswill be assumed to be of the typeTraversable[Any]by the compiler, even if the collection being observed is of typeX, in which case it should beTraversable[X]. In order to get the expected behavior from the compiler, we must say that we specifically wantTraversable[X](note that this will also generate an annoying erasure warning):changes.foreach { case Add(_, elements: Traversable[X]) => // do your stuff }and we cannot do
changes.foreach { case Add[X](_ elements) => // do your stuff }as that is actually invalid syntax.
If
Changewere to have a type parameterT, one could specify the type ofChangeswhen adding aChangeListenerto a buffer:onChange { (collection: ObservableBuffer[X], changes: Seq[Change[X]]) => changes.foreach { case Add(_, elements) => // do your stuff with Traversable[X] } }As it stands right now, this would require is modifying the class signatures for operations to accept a type, and in the case of operation cases where type is unimportant (such as
Reorder), the typeAnymay be specified when inheritingChange, or can be specified and implicitly inferred.