如何
yield
作品它被转换为
flatMap
(参见
here
)。那么,让我们试着用
平面图
对于不可编译版本,使用显式类型:
val eithert1: EitherT[Future, IsNegative, Int] = EitherT(isPos(i))
def eithert2(ret: Int): EitherT[Future, IsPositive, Int] = EitherT(isNeg(ret))
eithert1.flatMap(ret => eithert2(ret)).map(ret2 => ret2)
现在您有哪些类型:
// What is expected (see `EitherT` type bounds in sources, I copied here)
// flatMap -> EitherT[F[_], A, B].flatMap[AA >: A, D](f: B => EitherT[F, AA, D])
// what you have:
// EitherT[Future, IsNegative, Int].flatMap[IsPositive >: IsNegative, Int](f: Int => EitherT[Future, IsPositive, Int])
您可以看到:
IsPositive >: IsNegative
,这是错误的。预期的超级类型
IsNegative
(或者
Error
或
Is阴性
)