Cats currently have an open delete request to add the semiflatMap method to OptionT and XorT , which accepts the function B => F[C] .
We could create a similar function for scalaz.EitherT :
import scalaz._, Scalaz._ def semiFlatMap[F[_]: Monad, A, B, C](e: EitherT[F, A, B])(f: B => F[C]): EitherT[F, A, C] = e.flatMap(f andThen EitherT.right[F, A, C])
Then you could do:
import scala.concurrent.Future import scala.concurrent.ExecutionContext.Implicits.global val futureEither: Future[Either[String, Int]] = Future.successful(Right(1)) val f: Int => Future[Long] = i => Future.successful(i + 1L) val appliedF: EitherT[Future,String,Long] = semiFlatMap(EitherT.fromEither(futureEither))(f) val futureEither2: Future[Either[String, Long]] = appliedF.run.map(_.toEither)
source share