Skip to content

Commit 05ebd99

Browse files
author
Martijn Hoekstra
committed
incorporate review
1 parent f8496bd commit 05ebd99

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

_tour/multiple-parameter-lists.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,33 @@ Suggested use cases for multiple parameter lists include:
3939
#### Drive type inference
4040

4141
It so happens that in Scala, type inference proceeds one parameter list at at time.
42-
Say, you have the following method:
42+
Say you have the following method:
4343

4444
```tut
45-
def foldleft1[A, B](as: List[A], b0: B, op: (B, A) => B) = ???
45+
def foldLeft1[A, B](as: List[A], b0: B, op: (B, A) => B) = ???
4646
```
4747

4848
Then you'd like to call it in the following way, but will find that it doesn't compile:
4949

5050
```tut:fail
51-
def notpossible = foldleft1(numbers, 0, _ + _)
51+
def notPossible = foldLeft1(numbers, 0, _ + _)
5252
```
5353

5454
you will have to call it like one of the below ways:
5555

5656
```tut
57-
def firstWay = foldleft1[Int, Int](numbers, 0, _ + _)
58-
def secondWay = foldleft1(numbers, 0, (a: Int, b: Int) => a + b)
57+
def firstWay = foldLeft1[Int, Int](numbers, 0, _ + _)
58+
def secondWay = foldLeft1(numbers, 0, (a: Int, b: Int) => a + b)
5959
```
6060

61-
That's because scala won't be able to infer the type of the function `_ + _`, as it's still inferring `A` and `B`. By moving the parameter `op` to its own parameter list, `A` and `B` are inferred in the first parameter list. These inferred types will then be available to the second parameter list and `_ + _` will match the the inferred type `(Int, Int) => Int`
61+
That's because Scala won't be able to infer the type of the function `_ + _`, as it's still inferring `A` and `B`. By moving the parameter `op` to its own parameter list, `A` and `B` are inferred in the first parameter list. These inferred types will then be available to the second parameter list and `_ + _` will match the the inferred type `(Int, Int) => Int`
6262

6363
```tut
64-
def foldleft2[A, B](as: List[A], b0: B)(op: (B, A) => B) = ???
65-
def possible = foldleft2(numbers, 0)(_ + _)
64+
def foldLeft2[A, B](as: List[A], b0: B)(op: (B, A) => B) = ???
65+
def possible = foldLeft2(numbers, 0)(_ + _)
6666
```
6767

68-
This definition doesn't need any type hints and can infer all of its parameters.
68+
This definition doesn't need any type hints and can infer all of its type parameters.
6969

7070

7171
#### Implicit parameters

0 commit comments

Comments
 (0)