New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

`ObservableBuffer.Change` has no generic type parameters, while the majority of its children do #184

Closed
RomanHargrave opened this Issue Feb 23, 2015 · 0 comments

Comments

Projects
None yet
2 participants
@RomanHargrave
Contributor

RomanHargrave commented Feb 23, 2015

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.

@RomanHargrave RomanHargrave changed the title from `ObservableBuffer.Change` is has no generic type parameters, while the majority of its children do to `ObservableBuffer.Change` has no generic type parameters, while the majority of its children do Feb 24, 2015

@jpsacha jpsacha added the bug label Oct 30, 2015

@jpsacha jpsacha added this to the 8.0.*-R10 milestone Oct 30, 2015

jpsacha added a commit that referenced this issue Nov 27, 2015

@jpsacha jpsacha closed this Nov 27, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment