From 56483db361b6f5d5d9a706fafb57e8339cde95ee Mon Sep 17 00:00:00 2001 From: Ben Luo Date: Thu, 6 Oct 2022 19:55:04 +0800 Subject: [PATCH 1/3] add code tabs in num15. --- _overviews/scala3-book/taste-toplevel-definitions.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/_overviews/scala3-book/taste-toplevel-definitions.md b/_overviews/scala3-book/taste-toplevel-definitions.md index 604ee0a0dd..8091ef297c 100644 --- a/_overviews/scala3-book/taste-toplevel-definitions.md +++ b/_overviews/scala3-book/taste-toplevel-definitions.md @@ -12,6 +12,8 @@ next-page: taste-summary In Scala 3, all kinds of definitions can be written at the “top level” of your source code files. For instance, you can create a file named _MyCoolApp.scala_ and put these contents into it: +{% tabs toplevel_1 class=tabs-scala-version %} +{% tab 'Scala 3 only' for=toplevel_1 %} ```scala import scala.collection.mutable.ArrayBuffer @@ -37,15 +39,18 @@ type Money = BigDecimal p.toppings += Cheese println("show me the code".capitalizeAllWords) ``` +{% endtab %} +{% endtabs %} As shown, there’s no need to put those definitions inside a `package`, `class`, or other construct. - ## Replaces package objects If you’re familiar with Scala 2, this approach replaces _package objects_. But while being much easier to use, they work similarly: When you place a definition in a package named _foo_, you can then access that definition under all other packages under _foo_, such as within the _foo.bar_ package in this example: +{% tabs toplevel_2 class=tabs-scala-version %} +{% tab 'Scala 3 only' for=toplevel_2 %} ```scala package foo { def double(i: Int) = i * 2 @@ -58,9 +63,9 @@ package foo { } } ``` +{% endtab %} +{% endtabs %} Curly braces are used in this example to put an emphasis on the package nesting. The benefit of this approach is that you can place definitions under a package named _com.acme.myapp_, and then those definitions can be referenced within _com.acme.myapp.model_, _com.acme.myapp.controller_, etc. - - From 5f3836349f4770e156375e2bac37a65fa927937f Mon Sep 17 00:00:00 2001 From: Ben Luo Date: Fri, 7 Oct 2022 23:21:21 +0800 Subject: [PATCH 2/3] Update _overviews/scala3-book/taste-toplevel-definitions.md Co-authored-by: Jamie Thompson --- _overviews/scala3-book/taste-toplevel-definitions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_overviews/scala3-book/taste-toplevel-definitions.md b/_overviews/scala3-book/taste-toplevel-definitions.md index 8091ef297c..07a2a20ef7 100644 --- a/_overviews/scala3-book/taste-toplevel-definitions.md +++ b/_overviews/scala3-book/taste-toplevel-definitions.md @@ -12,7 +12,7 @@ next-page: taste-summary In Scala 3, all kinds of definitions can be written at the “top level” of your source code files. For instance, you can create a file named _MyCoolApp.scala_ and put these contents into it: -{% tabs toplevel_1 class=tabs-scala-version %} +{% tabs toplevel_1 %} {% tab 'Scala 3 only' for=toplevel_1 %} ```scala import scala.collection.mutable.ArrayBuffer From f2d96813c768acd428c5f27028895142d9fecd75 Mon Sep 17 00:00:00 2001 From: Ben Luo Date: Fri, 7 Oct 2022 23:26:53 +0800 Subject: [PATCH 3/3] correct 2&3 and 3 only. --- _overviews/scala3-book/taste-toplevel-definitions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_overviews/scala3-book/taste-toplevel-definitions.md b/_overviews/scala3-book/taste-toplevel-definitions.md index 07a2a20ef7..7448af41ed 100644 --- a/_overviews/scala3-book/taste-toplevel-definitions.md +++ b/_overviews/scala3-book/taste-toplevel-definitions.md @@ -49,7 +49,7 @@ As shown, there’s no need to put those definitions inside a `package`, `class` If you’re familiar with Scala 2, this approach replaces _package objects_. But while being much easier to use, they work similarly: When you place a definition in a package named _foo_, you can then access that definition under all other packages under _foo_, such as within the _foo.bar_ package in this example: -{% tabs toplevel_2 class=tabs-scala-version %} +{% tabs toplevel_2 %} {% tab 'Scala 3 only' for=toplevel_2 %} ```scala package foo {