You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def secondWay = foldLeft1(numbers, 0, (a: Int, b: Int) => a + b)
59
59
```
60
60
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`
62
62
63
63
```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)(_ + _)
66
66
```
67
67
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.
0 commit comments