Scala 集合中缺少 par 方法

Missing par method from Scala collections

我试图在 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。

导入的库依赖项:

正如@Thilo 在评论中提到的,我缺少以下自 Scala 2.13 以来必需的导入:

import scala.collection.parallel.CollectionConverters._

Source: https://github.com/scala/scala-parallel-collections/issues/22

除了进口:

import scala.collection.parallel.CollectionConverters._ 

你还需要在你的maven项目的pom.xml中添加依赖:

<dependency>
        <groupId>org.scala-lang.modules</groupId>
        <artifactId>scala-parallel-collections_2.13</artifactId>
        <version>0.2.0</version>
</dependency>