简体   繁体   中英

List[EitherT[Future, A, B]] to EitherT[Future, A, List[B]] with cats

I'm not able to transform a list of EitherT to a EitherT of list using cats 1.0.1:

import cats.implicits._

val list: List[EitherT[Future, String, Int]] = List(1.pure, 2.pure)
val eitherOfList : EitherT[Future, String, List[Int]] = list.sequence

The error is: the expression of type Nothing[List[Nothing]] doesn't conform to expected type EitherT[Future, String, List[Int]]

Sadly scala type inference isn't that great, so you'll have to annotate your code, when using the pure syntax.

type Stack[A] = EitherT[Future, String, A]

val list: List[Stack[Int]] = List(1.pure[Stack], 2.pure[Stack])
val eitherOfList: Stack[List[Int]] = list.sequence

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM