I try write code like something this, but I have no idea how to complete that task
db.find(uuid, accountName): Future[Option[Account]]
db.add(uuid, account): Future[Option[Account]]
def add(uuid: UUID, account: Account): Future[Either[String, Option[Account]]] =
db.find(userId, account.name).map {
case None =>
db.add(userId.uuid, account).map(Right(_))
case Some(existAccount) =>
Left(s"Account already exist $existAccount")
}Edit: This code can`t compile with error:
Error:(77, 41) type mismatch;
found : scala.concurrent.Future[scala.util.Right[Nothing,Option[Account]]]
required: Either[String,Option[Account]]
db.add(userId, account).map(Right(_))
^--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
def add(uuid: UUID, account: Account): Future[Either[String, Option[Account]]] = db.find(userId, account.name).map { case None =>
db.add(userId.uuid, account).flatMap { account: Option[Account] => Future.successful(Right[String, Option[Account]](account))
case Some(existAccount) => Future.successful(Left[String, Option[Account]](s"Account already exist $existAccount") }