File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed
Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ previous-page: nested-functions
1313
1414方法可以定义多个参数列表,当使用较少的参数列表调用多参数列表的方法时,会产生一个新的函数,该函数接收剩余的参数列表作为其参数。这被称为[ 柯里化] ( https://zh.wikipedia.org/wiki/%E6%9F%AF%E9%87%8C%E5%8C%96 ) 。
1515
16- 下面是一个例子,在Scala集合中定义的特质 [ Traversable ] ( /zh-cn/overviews/collections/ trait-traversable.html ) :
16+ 下面是一个例子,在Scala集合 ` trait TraversableOnce ` 定义了 ` foldLeft `
1717
1818```
1919def foldLeft[B](z: B)(op: (B, A) => B): B
@@ -33,11 +33,11 @@ print(res) // 55
3333
3434#### 单一的函数参数
3535 在某些情况下存在单一的函数参数时,例如上述例子` foldLeft ` 中的` op ` ,多参数列表可以使得传递匿名函数作为参数的语法更为简洁。如果不使用多参数列表,代码可能像这样:
36-
36+
3737```
3838numbers.foldLeft(0, {(m: Int, n: Int) => m + n})
3939```
40-
40+
4141 注意使用多参数列表时,我们还可以利用Scala的类型推断来让代码更加简洁(如下所示),而如果没有多参数列表,这是不可能的。
4242
4343```
@@ -68,13 +68,13 @@ numbers.foldRight(0)(_+_) // Curried Form
6868
6969(0 /: numbers)(_+_) // Used in place of foldLeft
7070(numbers :\ 0)(_+_) // Used in place of foldRight
71- ```
71+ ```
72+
7273
73-
7474#### 隐式(implicit)参数
7575 如果要指定参数列表中的某些参数为隐式(implicit),应该使用多参数列表。例如:
7676
7777```
7878def execute(arg: Int)(implicit ec: ExecutionContext) = ???
7979```
80-
80+
You can’t perform that action at this time.
0 commit comments