We have a user class with the ability to regenerate the identifier:
case class User(id: Long, nick: String) {
def regenerateUserId(regenerate: Long => Long): User = {
val newId = regenerate(this.id)
this.copy(id = newId)
}
}
We wrote a function for regeneration:
def idToNewFormat(id: Int): Int =
id + 10000
Scala shows type mismatch at compile time. Fix the method so that we can pass it to the method as follows:
val user = User(42L, "Nick")
val updated = user.regenerateUserId(idToNewFormat)