The easiest way to do this is sequence
inside Option
, so that you receive Either[Error, Either[Error, Option[Account]]]
and then smooth it. With cat syntax, this is very simple:
import cats.implicits._
val target: Either[Error, Option[Account]] =
data.flatMap(_.sequence)
, sequence
"", Option[Either[Error, Account]]
Either[Error, Option[Account]]
.