Re: ignorance: customizable immutables?
Andrew Phillips <[email protected]>
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <[email protected]> |
so a new type of A is constructed not AStar.
In that case, I probably misunderstood the question. Are we assuming here
that there is some kind of generic scheme that returns new immutables,
simply based on the inferred type of the instance and the new values?
I had something along these lines in mind:
class A(v: Int = 0) {
val value = v
def foo = "normal"
def withValue(newValue: Int = value) = new A(newValue)
}
class AStar(v: Int = 0) extends A(v) {
override def foo = "different"
override def withValue(newValue: Int = value) = new AStar(newValue)
}
scala> val transformed = List(new A, new AStar) map { _.withValue(42) }
transformed: List[A] = List(A@16c933d, AStar@7f368a85)
scala> transformed foreach { a => println(a.value + ", " + a.foo) }
42, normal
42, different
This seems to me to be in line with the notion of "immutables that respect
whatever customization has been done", but requires the operation that
returns the new immutable to be overridden for each customizing class. That
may well not count as a "concise and robust" scheme, indeed.
Regards
ap
--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.