Folding EitherT[Future, Throwable, A]

940 Views Asked by At

Cannot figure out most idiomatic way to kinda fold EitherT[Future, Throwable, A] to Future[A], where left side of Either will be represented as failed Future.

2

There are 2 best solutions below

0
On

Is a simple straight-forward fold not good?

 foo.fold(Future.failed, Future.successful).flatten
0
On

You could use fold and throw whatever Throwable you find on the left side

val foo: EitherT[Future, Throwable, A] = ???

import cats.instances.future._

foo.fold(throw _, identity)