I have the following class built:
class Player(val name: String, val onField: Boolean, val draft: Int, val perc: Int, val height: Int, val timePlayed: Int) {
override def toString: String = name
}
I'm trying to do
def play(team: List[Player]): List[Player] =
team map (p => new Player(p.name, p.onField, p.draft, p.perc, p.height, p.timePlayed + 1))
which is actually incrementing the field "timePlayed" by one, and return the new "List" of players.
Is there a more convenient way to do this? Perhaps:
def play(team: List[Player]): List[Player] =
team map (p => p.timeIncremented())
My question is how to implement timeIncremented() in a more convenient way? so that I don't have to do:
new Player(p.name, p.onField, p.draft, p.perc, p.height, p.timePlayed + 1)
Thanks!