Folding EitherT[Future, Throwable, A]

935 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 answers

0
AudioBubble On

Is a simple straight-forward fold not good?

 foo.fold(Future.failed, Future.successful).flatten
0
Stefano Bonetti 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)