Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions _tour/multiple-parameter-lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,22 @@ numbers.foldLeft(0, {(m: Int, n: Int) => m + n})
```
numbers.foldLeft(0)(_ + _)
```

Also, it allows us to fix the parameter `z` and pass around a partial function and reuse it as shown below:

Finally, `foldLeft` and `foldRight` can be used in any of the following terms,
```tut
val numbers = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

numbers.foldLeft(0)((sum, item) => sum + item) // Generic Form
numbers.foldRight(0)((sum, item) => sum + item) // Generic Form

numbers.foldLeft(0)(_+_) // Curried Form
numbers.foldRight(0)(_+_) // Curried Form

(0 /: numbers)(_+_) // Used in place of foldLeft
(numbers :\ 0)(_+_) // Used in place of foldRight
```

Above statement `numbers.foldLeft(0)(_ + _)` allows us to fix the parameter `z` and pass around a partial function and reuse it as shown below:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you mean here "the statement below"?

```tut
val numbers = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
val numberFunc = numbers.foldLeft(List[Int]())_
Expand All @@ -64,4 +78,4 @@ print(cubes.toString()) // List(1, 8, 27, 64, 125, 216, 343, 512, 729, 1000)
```
def execute(arg: Int)(implicit ec: ExecutionContext) = ???
```