Skip to content

Commit 40565ef

Browse files
authored
Merge pull request #3156 from AlecVercruysse/patch-1
separate Scala 2/3 example for partial application in _tour/multiple-parameter-lists.md
2 parents 32b50ed + f030f97 commit 40565ef

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

_tour/multiple-parameter-lists.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ When a method is called with a fewer number of parameter lists, then this will y
143143

144144
For example,
145145

146-
{% tabs foldLeft_partial %}
146+
{% tabs foldLeft_partial class=tabs-scala-version %}
147147

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

161+
{% tab 'Scala 3' for=foldLeft_partial %}
162+
```scala
163+
val numbers = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
164+
val numberFunc = numbers.foldLeft(List[Int]())
165+
166+
val squares = numberFunc((xs, x) => xs :+ x*x)
167+
println(squares) // List(1, 4, 9, 16, 25, 36, 49, 64, 81, 100)
168+
169+
val cubes = numberFunc((xs, x) => xs :+ x*x*x)
170+
println(cubes) // List(1, 8, 27, 64, 125, 216, 343, 512, 729, 1000)
171+
```
172+
{% endtab %}
173+
161174
{% endtabs %}
162175

163176
### Comparison with "currying"

0 commit comments

Comments
 (0)