Errors at every step, help!

Report a typo

We have several functions in our implemented API:

def findUser(id: Long): Option[User]

case object UsernameAlreadyOccupied
def updateUsername(user: User, username: String): Either[UsernameAlreadyOccupied.type, User]

case object ConnectionError
def saveUser(user: User): Either[ConnectionError.type, Unit]

We need a function that will take an id with a new username and get the data, update the user, and save it in the data warehouse using the functions above. Implement this function but keep in mind that we need our own error tree for it, which has already been implemented.

Sample Input 1:

42 terminator

Sample Output 1:

Right(())
Write a program in Scala 3
sealed trait UpdatingError
case class NoUser(id: Long) extends UpdatingError
case class UseAnotherUsername(username: String) extends UpdatingError
case object InternalError extends UpdatingError

def updateUsernameFor(id: Long, newUsername: String): Either[UpdatingError, Unit] =
for
user <- ???
updated <- ???
??? <- ???
yield ???
___

Create a free account to access the full topic