You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _overviews/scala3-book/domain-modeling-fp.md
+5-21Lines changed: 5 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -59,7 +59,7 @@ In Scala, describing the data model of a programming problem is simple:
59
59
Data that simply consists of different alternatives, like crust size, crust type, and toppings, is concisely modeled with the Scala 3 `enum` construct:
60
60
61
61
{% tabs data_1 %}
62
-
{% tab 'Scala 3 only' for=data_1 %}
62
+
{% tab 'Scala 3 Only' for=data_1 %}
63
63
64
64
```scala
65
65
enumCrustSize:
@@ -82,24 +82,8 @@ enum Topping:
82
82
A pizza can be thought of as a _compound_ container of the different attributes above.
83
83
We can use a `case` class to describe that a `Pizza` consists of a `crustSize`, `crustType`, and potentially multiple `Topping`s:
84
84
85
-
{% tabs data_2 class=tabs-scala-version %}
86
-
{% tab 'Scala 2' for=data_2 %}
87
-
88
-
```scala
89
-
importCrustSize._
90
-
importCrustType._
91
-
importTopping._
92
-
93
-
caseclassPizza(
94
-
crustSize: CrustSize,
95
-
crustType: CrustType,
96
-
toppings: Seq[Topping]
97
-
)
98
-
```
99
-
100
-
{% endtab %}
101
-
102
-
{% tab 'Scala 3' for=data_2 %}
85
+
{% tabs data_2 %}
86
+
{% tab 'Scala 3 Only' for=data_2 %}
103
87
104
88
```scala
105
89
importCrustSize.*
@@ -325,7 +309,7 @@ A first approach is to define the behavior---the functions---in a companion obje
325
309
With this approach, in addition to the enumeration or case class you also define an equally named companion object that contains the behavior.
326
310
327
311
{% tabs org_1 %}
328
-
{% tab 'Scala 3 only' for=org_1 %}
312
+
{% tab 'Scala 3 Only' for=org_1 %}
329
313
330
314
```scala
331
315
caseclassPizza(
@@ -660,7 +644,7 @@ This can have multiple advantages:
0 commit comments