简体   繁体   中英

Cats EitherT convert to Future[Result]

I have result like:

EitherT[Future, IllegalStateException, Result]

how to convert to Future[Result]? And let Future fail with this IllegalStateException? I know I can do like resultT.value to get Future[Either[Exception, Res]] and convert it but maybe there is simpler way.

There isn't really any simpler version to do it than what you've mentioned. But the conversion isn't hard to do either, so there isn't really a need.

import scala.util.chaining._
resultT.value.flatMap(_.toTry.pipe(Future.fromTry))

As I always say, the Scaladoc is your friend.

All you need to do is:

resultT.rethrowT

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM