What I want to do:
class ListField[+T] extends Field[MutableList[T]] {
value = Some(new MutableList[T]())
def +=[S >: T](newValue: S): Unit = add(newValue)
def add[S >: T](newValue: S): Unit = value.map(l => {
if (writable_? || !initialized_?) {
In the next line, I get:
type mismatch; found: newValue.type (with base type S) required: T
l += newValue
validate
makeDirty
change0.fire(l)
}
})
def length: Int = list.length
How should I do it? Is it possible? If I do not do the T-co-option, everything works as it is.
Field:
class Field[T] extends Signal[T] with ChangeStateTracking {
private[this] var data: Option[T] = None
private var writable = true
def writable_? = writable
override def now = data.get
def value: Option[T] = data
def validate: ValidationNel[FieldError, Option[T]] = value.successNel[FieldError]
//etc
NOTE. The code really works and compiles if I don't want T to be covariant (i.e. T instead of + T). This is only when I try to make T covariant to get an error.
I need an extra list + T, which may change.
source
share