我正在了解有关 Scala 的更多信息,并且在理解http://www.scala-lang.org/node/135中的匿名函数示例时遇到了一些麻烦。我复制了下面的整个代码块:
object CurryTest extends Application {
def filter(xs: List[Int], p: Int => Boolean): List[Int] =
if (xs.isEmpty) xs
else if (p(xs.head)) xs.head :: filter(xs.tail, p)
else filter(xs.tail, p)
def modN(n: Int)(x: Int) = ((x % n) == 0)
val nums = List(1, 2, 3, 4, 5, 6, 7, 8)
println(filter(nums, modN(2)))
println(filter(nums, modN(3)))
}
我对 modN 函数的应用感到困惑
def modN(n: Int)(x: Int) = ((x % n) == 0)
在示例中,它使用一个参数调用
modN(2) and modN(3)
modN(n: Int)(x: Int) 的语法是什么意思?
由于它是用一个参数调用的,我假设它们不是两个参数,但我无法真正弄清楚 mod 函数如何使用来自 nums 的值。