我试图在Intellij中将顺序列表转换为并行列表,但出现错误
Cannot resolve symbol par
在
.par
方法调用上:import scala.collection.parallel.immutable._
...
val parList = List(1,2,3).par
根据https://docs.scala-lang.org/overviews/parallel-collections/overview.html,一个人必须简单地
invoke the par method on the sequential collection, list. After that, one can use a parallel collection in the same way one would normally use a sequential collection.
让我感到奇怪的是,我在scala的当前不可变列表api中没有找到任何
par
方法:https://www.scala-lang.org/api/current/scala/collection/immutable/List.html但是,甚至还有一个专用的scala文档页面,用于使用
par
方法的顺序到并行转换:https://docs.scala-lang.org/overviews/parallel-collections/conversions.html关于我的设置
我在Arch Linux上,将OpenJDK 10设置为语言级别9(在Intellij中)和scala-sdk-2.13.0。
导入的库依赖项:
scala-library
(2.13.0)scala-parallel-collections
(2.13.0)最佳答案
正如@Thilo在评论中提到的那样,我缺少以下导入,这是从Scala 2.13开始所必需的:import scala.collection.parallel.CollectionConverters._
Source: https://github.com/scala/scala-parallel-collections/issues/22
关于scala - Scala集合中缺少par方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57287607/