In my current project, I used Either[Result, HandbookModule] (Result is an HTTP Statuscode) as a return type so that I can create the correct status when something goes wrong. I have now refactored my database access to be non-blocking.
This change requires that my return type for database access functions changed to Future[Either[Result, HandbookModule]].
Now I am not sure on how to glue this function together with another function which returns Either[Result, Long].
So to better illustrate what I mean:
def moduleDao.getHandbooks(offset, limit): Future[Either[Result, List[Module]] = Future(Right(List(Module(1))))
def nextOffset(offset, limit, results): Either[_, Long] = Right(1)
def getHandbooks(
offset: Long,
limit: Long): Future[Either[Result, (List[HandbookModule], Long)]] = {
for {
results <- moduleDao.getHandbooks(offset, limit)
offset <- nextOffset(offset, limit, results)
} yield (results, offset)
}
Before the change, this was obviously no problem but I don't know what would be the best approach.
Or is there a way to convert a Future[Either[A, B]] to an Either[A, Future[B]]?