Where does for-comprehension stop?

Report a typo

We have several implemented functions:

def makeBuy(itemId: Long, cost: BigDecimal): Either[String, Unit]
def getItemCost(itemId: Long): Either[String, BigDecimal]
def enoughBalance(cost: BigDecimal): Boolean

We also have a function that aggregates actions:

def buyItem(itemId: Long): Either[String, Unit] =
  for
    _ <- Right { println(s"Start buying item: $itemId") }
    itemCost <- getItemCost(itemId)
    _ <- Either.cond(enoughBalance(itemCost), (), "Error: not enough balance")
    _ <- makeBuy(itemId, itemCost)
    _ <- Right { println("Finished buy process") }
  yield ()

What will be printed to the console if we call buyItem with itemId=42, and getItemCost returns a Right value with a price, and enoughBalance returns false?

Select one option from the list
___

Create a free account to access the full topic