Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

separate Scala 2/3 example for partial application in _tour/multiple-parameter-lists.md #3156

Merged
merged 2 commits into from
Feb 22, 2025
Merged
Changes from all commits
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
17 changes: 15 additions & 2 deletions _tour/multiple-parameter-lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ When a method is called with a fewer number of parameter lists, then this will y

For example,

{% tabs foldLeft_partial %}
{% tabs foldLeft_partial class=tabs-scala-version %}

{% tab 'Scala 2 and 3' for=foldLeft_partial %}
{% tab 'Scala 2' for=foldLeft_partial %}
```scala mdoc:nest
val numbers = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
val numberFunc = numbers.foldLeft(List[Int]()) _
Expand All @@ -158,6 +158,19 @@ println(cubes) // List(1, 8, 27, 64, 125, 216, 343, 512, 729, 1000)
```
{% endtab %}

{% tab 'Scala 3' for=foldLeft_partial %}
```scala
val numbers = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
val numberFunc = numbers.foldLeft(List[Int]())

val squares = numberFunc((xs, x) => xs :+ x*x)
println(squares) // List(1, 4, 9, 16, 25, 36, 49, 64, 81, 100)

val cubes = numberFunc((xs, x) => xs :+ x*x*x)
println(cubes) // List(1, 8, 27, 64, 125, 216, 343, 512, 729, 1000)
```
{% endtab %}

{% endtabs %}

### Comparison with "currying"
Expand Down