Scala 使用嵌套的CAT映射一系列未来?

Scala 使用嵌套的CAT映射一系列未来?,scala,scala-cats,Scala,Scala Cats,使用Ammonite REPL,我能够复制嵌套猫的这一部分: 万岁!这很有效。但是,当我试图在未来的序列结果上做同样的事情时,map为什么不存在呢 @ val nestedFutureSeq = Nested(Future.successful(List(1))) nestedFutureSeq: Nested[Future, List, Int] = Nested(Future(Success(List(1)))) @ nestedFutureSeq.map(_.toString) cmd5

使用Ammonite REPL,我能够复制嵌套猫的这一部分:

万岁!这很有效。但是,当我试图在
未来
序列
结果上做同样的事情时,
map
为什么不存在呢

@ val nestedFutureSeq = Nested(Future.successful(List(1)))
nestedFutureSeq: Nested[Future, List, Int] = Nested(Future(Success(List(1))))

@ nestedFutureSeq.map(_.toString)
cmd5.sc:1: value map is not a member of cats.data.Nested[scala.concurrent.Future,List,Int]
did you mean mapK?
val res5 = nestedFutureSeq.map(_.toString)
                           ^
Compilation Failed

Future
Seq
都定义了
map
,所以这似乎是可能的。我可以使用
Nested
来执行此操作吗?如果可以,如何执行?

map
Nested上运行,前提是这两种类型都有Functor的实例。
FutureFunctor需要和
implicit
ExecutionContext的作用域,因为Future中的所有方法都需要它

因此,如果您添加这样一行(或将隐式ec放入范围的任何其他形式):

你会得到你期望的结果

nestedFutureSeq.map(_.toString)
// res: Nested[Future, List, String] = Nested(Future(Success(List(1))))

map
onNested如果两种类型都有一个Functor的实例,那么它就可以工作。
FutureFunctor需要和
implicit
ExecutionContext的作用域,因为Future中的所有方法都需要它

因此,如果您添加这样一行(或将隐式ec放入范围的任何其他形式):

你会得到你期望的结果

nestedFutureSeq.map(_.toString)
// res: Nested[Future, List, String] = Nested(Future(Success(List(1))))
nestedFutureSeq.map(_.toString)
// res: Nested[Future, List, String] = Nested(Future(Success(List(1))))