我正在编写一个用于理解的代码,并且想知道一些事情:
def updateUserStats(user: User): Either[Error,User] = for {
  stampleCount <- stampleRepository.getStampleCount(user).right
  userUpdated <- Right(copyUserWithStats(user,stampleCount)).right // ?????????
  userSaved <- userService.update(userUpdated).right
} yield userSaved
def copyUserWithStats(user: User, stamples: Long): User = {
  val newStats = user.userStats.copy(stamples = stamples)
  user.copy(userStats = newStats)
}
似乎使用不返回 Either 的 copyUserWithStats 不能直接在 for 理解中使用,因为它没有 map/flatMap 方法。
所以我想知道,在这种情况下,使用它是合适的解决方案Right(copyUserWithStats(user,stampleCount)).right 
它似乎至少可以工作......
顺便说一句,我也尝试了 Option 但它没有用,有人可以解释为什么吗?
def updateUserStats(user: User): Either[Error,User] = for {
  stampleCount <- stampleRepository.getStampleCount(user).right
  userUpdated <- Some(copyUserWithStats(user,stampleCount))
  userSaved <- userService.update(userUpdated).right
} yield userSaved
谢谢