Make a safe transfer!

Report a typo

Take a look at the implemented functions in our banking system:

def getUser(id: Long): Either[String, User]

def validateEnoughBalance(user: User, amountToCheck: BigDecimal): Either[String, Unit]

def applyTransfer(from: User, to: User, amount: BigDecimal): Either[String, Unit]

The implementation of the User class is hidden on purpose. Use for-comprehension to combine the methods and write a method that will get users by ID, check sender balance, and make a money transfer.

Sample Input 1:

from,to,amount
1,2,100

Sample Output 1:

success
Write a program in Scala 3
def makeTransfer(fromId: Long, toId: Long, amount: BigDecimal): Either[String, Unit] =
for
from <- ???
_ <- ???
to <- ???
_ <- ???
yield ()
___

Create a free account to access the full topic