Skip to content

add code tabs in num22. #2592

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

Merged
merged 4 commits into from
Oct 17, 2022
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
Prev Previous commit
Next Next commit
change to Scala 3 Only.
  • Loading branch information
benluo committed Oct 14, 2022
commit 9bd1fd1b48e3d8e1aee98620d5602463f5816e97
26 changes: 5 additions & 21 deletions _overviews/scala3-book/domain-modeling-fp.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ In Scala, describing the data model of a programming problem is simple:
Data that simply consists of different alternatives, like crust size, crust type, and toppings, is concisely modeled with the Scala 3 `enum` construct:

{% tabs data_1 %}
{% tab 'Scala 3 only' for=data_1 %}
{% tab 'Scala 3 Only' for=data_1 %}

```scala
enum CrustSize:
Expand All @@ -82,24 +82,8 @@ enum Topping:
A pizza can be thought of as a _compound_ container of the different attributes above.
We can use a `case` class to describe that a `Pizza` consists of a `crustSize`, `crustType`, and potentially multiple `Topping`s:

{% tabs data_2 class=tabs-scala-version %}
{% tab 'Scala 2' for=data_2 %}

```scala
import CrustSize._
import CrustType._
import Topping._

case class Pizza(
crustSize: CrustSize,
crustType: CrustType,
toppings: Seq[Topping]
)
```

{% endtab %}

{% tab 'Scala 3' for=data_2 %}
{% tabs data_2 %}
{% tab 'Scala 3 Only' for=data_2 %}

```scala
import CrustSize.*
Expand Down Expand Up @@ -325,7 +309,7 @@ A first approach is to define the behavior---the functions---in a companion obje
With this approach, in addition to the enumeration or case class you also define an equally named companion object that contains the behavior.

{% tabs org_1 %}
{% tab 'Scala 3 only' for=org_1 %}
{% tab 'Scala 3 Only' for=org_1 %}

```scala
case class Pizza(
Expand Down Expand Up @@ -660,7 +644,7 @@ This can have multiple advantages:
Let us revisit our example once more.

{% tabs module_7 %}
{% tab 'Scala 3 only' for=module_7 %}
{% tab 'Scala 3 Only' for=module_7 %}

```scala
case class Pizza(
Expand Down