Reputation: 48410
How to lift \/[Error, Int]
into EitherT[Future, Error, Int]
using point/liftM
syntax such that lifting is on the right-hand side?
I have the following scenario
for {
r1 <- f1: EitherT[Future, Error, Int]
r2 <- v: \/[Error, Int]
r3 <- f2: EitherT[Future, Error, Int]
} yield r3
I can make v
fit by applying EitherT.fromDisjunction[Future]
like so
for {
r1 <- f1
r2 <- EitherT.fromDisjunction[Future](v)
r3 <- f2
} yield r3
or simply
for {
r1 <- f1
r2 <- EitherT(Future(v))
r3 <- f2
} yield r3
however I am trying to move the lifting magic to the right-hand-side of v
like so
for {
r1 <- f1
r2 <- v.point[Future].liftM[EitherT] // something approximately like this
r3 <- f2
} yield r3
I tried
type Result[F[_], A] = EitherT[F, Error, A]
v.point[Future].liftM[Result]
and
v.point[({ type L[x] = EitherT[Future, Error, x] })#L]
suggested here and here, however this types to
EitherT[Future, Error, Error \/ Int]
whilst I require
EitherT[Future, Error, Int]
Moving lifting to the right-hand-side is just for aesthetics, as EitherT.fromDisjunction[Future]
works fine.
Upvotes: 4
Views: 125
Reputation: 51658
It's just
r2 <- v.eitherT[Future, Error, Int]
with
import scalaz.{EitherT, \/}
import scalaz.std.scalaFuture._
import scalaz.syntax.eithert._
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scala.language.higherKinds
Upvotes: 3
Reputation: 4761
I am not sure if that exists in scalaz. There is no toEitherT[F]
on disjunction. However it is trivial to add new syntax:
implicit class EitherLiftSyntax[A, B](val self: A \/ B) extends AnyVal {
def liftT[M[_]]: EitherT[M, A, B] = EitherT.fromDisjunction[M](self)
}
As long as you have that in scope, you can say v.liftT[Future]
Upvotes: 1