问题标签 [scala-2.13]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
scala - Scala 集合中缺少 par 方法
我试图在 Intellij 中将顺序列表转换为并行列表,但出现错误
无法解析符号 par
在.par
方法调用上:
根据https://docs.scala-lang.org/overviews/parallel-collections/overview.html,必须简单地
在顺序集合 list 上调用 par 方法。之后,可以像通常使用顺序收集一样使用并行收集。
par
让我感到奇怪的是,我在 scala 的当前不可变列表 api 中没有找到任何方法: 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)
scala - Scala 2.13 (im)mutable .map with 'Nothing" reference
I'm upgrading a software scala based from scala 2.12 to scala 2.13. Some blocks of code was broken and fixing them I found a wierd behavior in an already existing code.
@Edit
Below we have an explanation of a use case of this problem.
The problem in general is the usage of the method .map in mutable or immutable maps since Scala 2.13. At the end of the question we have an easy way to reproduce, and further we have the answer.
Obs.:
The term variables used there is a business field, its not related to scala (or java) variables.
list is an Array[Long] containing idProject.
The return of p.getVariables is a Map[String, VariableSet].
So after the second .map (line 4), we have an Array[(Project, Map[String, VariableSet])]
The code is:
The problems comes at the 6th line, because after the upgrade it recognizes the set (pair._2.map(set => ) as type "Nothing" .
I tried line by line and it seems to work.
Like this:
The problem here is that in the 6th line of previous example I need the reference to the project associated to that flow.
Of course, there would be room to rewrite this in another way (continuing the work on the second example), but I have many many other cases like this and would like to know if its really supposed not to work anymore of if I miss something during the upgrade.
Thanks in advance!
@Edit
Easy way to reproduce:
Looks like scala 2.13 see an element of Mutable Map as 'Nothing' ?
scala - Scala 2.13 用什么代替 MutableList?
我正在将软件从 Scala 2.12.8 升级到 Scala 2.13,并发现根据许多指南(如this one )删除了集合 MutableList (scala.collection.mutable.MutableList )。
例如,本指南说这是一个已弃用的集合,所以这就是它被删除的原因,但我在以前的版本中找不到该类的任何弃用。
“已删除不推荐使用的集合(MutableList、immutable.Stack、其他)”
我还首先升级到 2.12.9(2.13.0 之前的最新版本)以检查是否有任何已弃用的注释给出了关于使用什么的建议,但在此版本中,该集合也未被弃用。
我搜索了这个问题,但找不到一个好的答案。这个问题对我和未来的升级都有好处。
在 Scala 2.13 中,我应该使用什么来代替 MutableList?
scala - 什么是 scala 2.13 解释器主类?
如果我在 PATH 中没有该scala
命令,或者我想专门运行 sbt 项目的 scala 版本——不使用——scala 2.13sbt console
会是什么sbt runMain
?
scala - Generate companion object for case class with methods (field = method)
Generate companion object for case class with scala-macros
some code example that i tried, it works i can get list of tuple (name -> type) but how to generate the object in the same scope?
Is it possible to annotate some case class and the generated companion make visible in the same scope?
goal:
scala - 如何在Scala中为没有早期初始化程序的超类构造函数创建参数
由于 Scala 2.13 早期的初始化程序已被弃用。
如何创建一个值以传递给应该计算(基于其他构造函数参数)并且完全私有的超类,所以在类初始化时它不能被传递?
直到今天我所做的一个例子是:
(这只是一个带有假类名的示例,因为我不能分享我的源代码)
如果我定义了一个特征,我不知道如何将值传递给超类而不暴露它并在类构造函数中覆盖它。
我看到 Dotty (Scala 3) 允许特征参数,但 Scala 2.13 不允许。
如果您知道解决方案,请提供一个带有解释的片段!谢谢!
scala - 如何在 scala 2.13+ 中找到 Seq 的最小值
在早期版本的 Scala 中,我曾经能够做这样的事情来获得最小值:
这看起来简单易懂。在 Scala 2.13.1 中,我收到此错误:
不推荐使用 object Ordering 中的 object DeprecatedFloatOrdering(自 2.13.0 起):有多种方式来订购 Floats(Ordering.Float.TotalOrdering、Ordering.Float.IeeeOrdering)。通过使用本地导入、分配隐式 val 或显式传递来指定一个。有关详细信息,请参阅他们的文档。
我在 Scala 文档中阅读了有关 TotalOrdering 和 IeeeOrdering 的信息,并没有成功寻找如何使用它们的示例,但我不明白。鉴于我的简单示例,找到最小值的新方法是什么?如果未指定,为什么它不能默认为早期行为?
scala - 对于 Scala 2.13,更新具有数百万更新的 LongMap、HashMap 或 TrieMap 的最快方法是什么?
目标
我有一个可变的 Map[Long, Long] 有数百万个条目。我需要使用数百万次更新进行多次更新迭代。我想尽快做到这一点。
背景
目前,最快的方法是使用单线程 mutable.LongMap[Long]。此类型针对 Long 类型作为键进行了优化。
其他地图类型似乎更慢 - 但我可能没有正确实现它们,因为我试图同时和/或并行进行更新但没有成功。在 Scala 中,并行更新地图可能实际上并没有发生或不可能。
从最快到最慢的顺序:
- LongMap[Long](从上方)
- TrieMap[长,长]
- ParTrieMap[长,长]
- HashMap[长,长]
- ParHashMap[长,长]
- ParMap[长,长]
如果更快的方法不可变,那也没关系,但我认为情况不会如此。可变映射可能最适合此用例。
生成测试数据和计时测试的代码
当前时间
带有上述代码的 LongMap[Long] 在我的 2018 MacBook Pro 上按以下时间完成:
- ~3.5 秒,numEntries = 1000 万
- ~100 秒,numEntries = 1 亿
scala - scala 2.13 - 编译插件时出错
我想创建一个 sbt 插件
这是我的项目
build.sbt 文件:
带有任务的主文件
在编译期间出现错误: java.lang.NoClassDefFoundError: scala/collection/immutable/StringOps 当我将版本更改为 2.12.6 - 编译成功。如何修复 2.13 中的错误?
scala - 尝试在 Scala 2.13 中使用 .par 给我“错误:值 par 不是成员”
我正在学习Scala。在参加 Martin Odersky 的 MOOC 时,我观看了他在 OSCON Java 2011 上题为“努力保持简单”的演讲。在他的演讲中,他使用这种.par
方法使一个集合平行。但是当我尝试.par
在 Scala 中使用时,例如:
我收到此错误:
.par
Scala 2.13中的方法发生了什么变化?