I have a function as follows:
def bar(x : Int) : Either[String, Future[Option[Foo]]] = {
Goo() recover { case e => Left("Some error string") }
}
As you can see, if the Future fails then it will hit the partial function inside the recover body. This will return Left and satisfies the left part of the Either type. What I am stuck on is how to return the Right if the Goo future completes successfully.
I tried the following:
def bar(x : Int) : Either[String, Future[Option[Foo]]] = {
Goo().map(x => Right(Future.successful(x))) recover { case e => Left("Some error string") }
}
However, I get a type error indicating that the return type for bar
is Future[Either[String, Future[Foo]]]
.
How can I return a Right(x)
where x
is some value of type Foo
?
UPDATE
def bar(x : Int) : Future[Either[String, Option[Foo]]] = {
Goo().map(x => Right(x)) recover { case e => Left("Some error string") }
}