I would like to programmatically bind the values sent to mixins to an instance, and I wonder if there is a more immutable way to do this, and then using a hidden mutable object. First of all, I want to use this for the registry. My current approach is not strictly unchanged after construction, any suggestions?
trait Numbers {
lazy val values = holding
private var holding = Set.empty[Int]
protected def includes(i:Int) {
holding += i
}
}
trait Odd extends Numbers{
includes(1)
includes(3)
includes(5)
includes(7)
includes(9)
}
trait Even extends Numbers {
includes(2)
includes(4)
includes(6)
includes(8)
}
It gives the result I want
val n = new Odd with Even
println(n.values)
Set(5, 1, 6, 9, 2, 7, 3, 8, 4)
source
share