scala - List[EitherT[Future, A, B]] 到 EitherT[Future, A, List[B]] 与猫

标签 scala scala-cats

我无法使用 cats 1.0.1 将 EitherT 列表转换为 EitherT 列表:

import cats.implicits._

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

错误是:Nothing[List[Nothing]] 类型的表达式不符合预期类型 EitherT[Future, String, List[Int]]

最佳答案

遗憾的是,scala 类型推断并不是那么好,因此在使用 pure 语法时,您必须对代码进行注释。

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

关于scala - List[EitherT[Future, A, B]] 到 EitherT[Future, A, List[B]] 与猫,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48359344/

相关文章:

Scala 的位置方差

scala - 如何告诉 sbt-proguard 包含 java *.jars?

haskell - 为什么 fmap 必须映射 List 的每个元素?

scala - 使用来自猫效应的种族可防止应用程序退出

scala - 如何在 Play Framework 中为 WebSocket 请求添加过滤器

scala - 在 IntelliJ 中使用猫库时的错误错误

scala - Scala 是否支持类型构造函数的部分应用?

scala - sbt 项目解决依赖很慢

scala - 使用 scala fs2 文件流从文件中删除过滤行