假设我有以下设置:
def foo: Either[Error, A] = ???
def bar: EitherT[Future, Error, B] = ???
case class Baz(a: A, b: B)
我如何使用理解来实例化该类Baz
?我尝试过:
val res = for {
a <- foo
b <- bar
} yield Baz(a, b)
但是,结果有类型Either[Error, Nothing]
。我不知道在这种情况下正确的返回类型是什么,但显然我不想要Nothing
...
正确的组合方式是什么Either
and EitherT
为了理解?
Use EitherT.fromEither
函数来创建EitherT
from Either
import cats.data._
import cats.implicits._
def foo[A]: Either[Error, A] = ???
def bar[B]: EitherT[Future, Error, B] = ???
case class Baz[A, B](a: A, b: B)
def res[A, B] = for {
a <- EitherT.fromEither[Future](foo[A])
b <- bar[B]
} yield Baz(a, b)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)