If I have a monad transformer type taking two type arguments, I can use liftM
to lift values into the transformed monad:
scala> val o = 1.point[List].liftM[OptionT]
o: scalaz.OptionT[List,Int] = OptionT(List(Some(1)))
However if I try the same thing with EitherT
it seems like I must use a type alias (or a type lambda):
scala> val e = 1.point[List].liftM[({type l[a[+_],b] = EitherT[a, String, b]})#l]
e: scalaz.EitherT[List,java.lang.String,Int] = scalaz.EitherTFunctions$$anon$14@3f8905ca
What's the proper way to do this? Ideally inferring the type argument for liftM
using the expected type of the expression (something like val blah: EitherT[List, String, Int] = 1.point[List].liftM
).
There doesn't appear to be a better way to handle multi-argument type constructors in general, but in the specific case of EitherT
, we can use EitherT.right
:
scala> val o: EitherT[List, String, Int] = EitherT.right(1.point[List])
o: scalaz.EitherT[List,String,Int] = scalaz.EitherTFunctions$$anon$14@12fa8880
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With