我发现使用不可变列表的想法取得了成功,但是当来到这里的这段代码时,我感到很困惑。我发现自己写的东西更像是 Java 而不是 Scala 风格。我更愿意使用List(...)
而不是,Buffer(...)
但我不知道如何将相同的修改不可变List
传递给下一个函数。guesses
也在eliminate(...)
.
任何可以帮助我使其成为 Scala 方式的建议都值得赞赏。谢谢
val randomGuesses = List(...) // some long list of random integers
val guesses = randomGuesses.zipWithIndex.toBuffer
for ( s <- loop()) {
val results = alphaSearch(guesses)
if (results.size == 1) {
guesses(resultes.head._2) = results.head._1
eliminate(guesses, resultes.head._2)
}
else {
val results = betaSearch(guesses)
if (results.size == 1) {
guesses(resultes.head._2) = results.head._1
eliminate(guesses, resultes.head._2)
} else {
val results = betaSearch(guesses)
if (results.size == 1) {
guesses(resultes.head._2) = results.head._1
eliminate(guesses, resultes.head._2)
}
}
}
}