I have the following code, and I was wondering why the list.head.effects =
part is necessary here. To my understanding, uniform access princile says that the list should be returned by just the list.head.effects
, at which point I could access the list. But to make the assignment actually work, I need to have it as it is below.
Would it be that it evaluates the Entrance :: list.head.effects
but does not assign it anywhere? Am I still too deep in the mutable world?
def addEntrance(list: List[Tile]) = list.head.effects = Entrance :: list.head.effects
case class Tile(x: Int, y: Int) {
var effects: List[_ >: Effect] = List()
}
case class Entrance extends Effect
In any case, is there a nicer way to do this?