gpt4 book ai didi

scala - Scala 中的 Shuffle 范围很奇怪

转载 作者:行者123 更新时间:2023-12-04 07:52:45 25 4
gpt4 key购买 nike

查看这个 REPL session (为了可读性我已经整理了它):

scala> val x = 1 to 10
x: Range.Inclusive = Range(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

scala> val y = x.toSeq
y: Range = Range(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

scala> x eq y
res14: Boolean = true

scala> util.Random.shuffle(y)
<console>:10: error: Cannot construct a collection of type scala.collection.AbstractSeq[Int] with elements of type Int based on a collection of type scala.collection.AbstractSeq[Int].
util.Random.shuffle(y)
^

scala> util.Random.shuffle(x)
res16: scala.collection.immutable.IndexedSeq[Int] = Vector(8, 3, 4, 2, 10, 9, 7, 5, 6, 1)

首先,无论类型不同,这都应该有效。 问题是“为什么?”

最佳答案

SI-6948,a bug由基本的scala破坏引起的。

这是一个 nice long commit message加上一些额外的解释。

关于scala - Scala 中的 Shuffle 范围很奇怪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30132008/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com