w
Size: a a a
w
KS
AT
AT
λ
Y
F[_] : Monad, S[_] : Monad
, а на выходе F[Either[String, Unit]]
?R
Y
Y
class UserLocaltyPointsService[F[_] : Monad, S[_] : Monad](ur: UserRepository[F], es: EmailService[S]) {
def addPoints(userId: UUID, pointsToAdd: Int): F[S[Either[String, Unit]]] = ur.findUser(userId).flatMap {
case None => implicitly[Monad[F]].pure(implicitly[Monad[S]].pure(Left("User not found")))
case Some(user) =>
val updated = user.copy(loyaltyPoints = user.loyaltyPoints + pointsToAdd)
for {
_ <- es.sendEmail(user.email, "Points added!", s"You now have ${updated.loyaltyPoints}")
_ <- ur.updateUser(updated)
} yield Right(())
}
}
ᛒ
ᛒ
R
Y
Oℕ
SK
ᛒ
YE