HOF type mismatch

Report a typo

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)

Sample Input 1:

42

Sample Output 1:

10042
Write a program in Scala 3
def idToNewFormat(id: Int): Int =
id + 10000
___

Create a free account to access the full topic