From 5b2d4d8df5fc334a5ea77f07ee57efdea24918d8 Mon Sep 17 00:00:00 2001 From: Alec Vercruysse Date: Tue, 4 Feb 2025 18:08:25 -0800 Subject: [PATCH 1/2] separate Scala 2/3 example for partial application in _tour/multiple-parameter-lists.md --- _tour/multiple-parameter-lists.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/_tour/multiple-parameter-lists.md b/_tour/multiple-parameter-lists.md index 632a5ab4fc..422f966978 100644 --- a/_tour/multiple-parameter-lists.md +++ b/_tour/multiple-parameter-lists.md @@ -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]()) _ @@ -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 mdoc:nest +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" From f030f978dee729f1ac4dd51c007d7df1a16c6852 Mon Sep 17 00:00:00 2001 From: Alec Vercruysse Date: Tue, 4 Feb 2025 20:04:44 -0800 Subject: [PATCH 2/2] remove mdoc check of Scala 3 example in _tour/multiple-parameter-lists.md --- _tour/multiple-parameter-lists.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_tour/multiple-parameter-lists.md b/_tour/multiple-parameter-lists.md index 422f966978..324795b6c0 100644 --- a/_tour/multiple-parameter-lists.md +++ b/_tour/multiple-parameter-lists.md @@ -159,7 +159,7 @@ println(cubes) // List(1, 8, 27, 64, 125, 216, 343, 512, 729, 1000) {% endtab %} {% tab 'Scala 3' for=foldLeft_partial %} -```scala mdoc:nest +```scala val numbers = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) val numberFunc = numbers.foldLeft(List[Int]())