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
+9-9Lines changed: 9 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -58,7 +58,7 @@ In Scala, describing the data model of a programming problem is simple:
58
58
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
-
{% tabs data_1 class=tabs-scala-version %}
61
+
{% tabs data_1 %}
62
62
{% tab 'Scala 3 only' for=data_1 %}
63
63
64
64
```scala
@@ -124,7 +124,7 @@ This solution is very concise because it doesn’t require the operations on a p
124
124
The data model is easy to read, like declaring the design for a relational database.
125
125
It is also very easy to create values of our data model and inspect them:
126
126
127
-
{% tabs data_3 class=tabs-scala-version %}
127
+
{% tabs data_3 %}
128
128
{% tab 'Scala 2 and 3' for=data_3 %}
129
129
130
130
```scala
@@ -140,7 +140,7 @@ println(myFavPizza.crustType) // prints Regular
140
140
We might go on in the same way to model the entire pizza-ordering system.
141
141
Here are a few other `case` classes that are used to model such a system:
142
142
143
-
{% tabs data_4 class=tabs-scala-version %}
143
+
{% tabs data_4 %}
144
144
{% tab 'Scala 2 and 3' for=data_4 %}
145
145
146
146
```scala
@@ -324,7 +324,7 @@ A first approach is to define the behavior---the functions---in a companion obje
324
324
325
325
With this approach, in addition to the enumeration or case class you also define an equally named companion object that contains the behavior.
326
326
327
-
{% tabs org_1 class=tabs-scala-version %}
327
+
{% tabs org_1 %}
328
328
{% tab 'Scala 3 only' for=org_1 %}
329
329
330
330
```scala
@@ -355,7 +355,7 @@ object Topping:
355
355
356
356
With this approach you can create a `Pizza` and compute its price like this:
357
357
358
-
{% tabs org_2 class=tabs-scala-version %}
358
+
{% tabs org_2 %}
359
359
{% tab 'Scala 2 and 3' for=org_2 %}
360
360
361
361
```scala
@@ -431,7 +431,7 @@ When you write a pure interface like this, you can think of it as a contract tha
431
431
What you might also do at this point is imagine that you’re the consumer of this API.
432
432
When you do that, it helps to sketch out some sample “consumer” code to make sure the API looks like what you want:
433
433
434
-
{% tabs module_2 class=tabs-scala-version %}
434
+
{% tabs module_2 %}
435
435
{% tab 'Scala 2 and 3' for=module_2 %}
436
436
437
437
```scala
@@ -633,7 +633,7 @@ Instead, they have their own reference to the current pizza instance as `this`.
633
633
634
634
Now you can use this new design like this:
635
635
636
-
{% tabs module_6 class=tabs-scala-version %}
636
+
{% tabs module_6 %}
637
637
{% tab 'Scala 2 and 3' for=module_6 %}
638
638
639
639
```scala
@@ -659,7 +659,7 @@ This can have multiple advantages:
659
659
660
660
Let us revisit our example once more.
661
661
662
-
{% tabs module_7 class=tabs-scala-version %}
662
+
{% tabs module_7 %}
663
663
{% tab 'Scala 3 only' for=module_7 %}
664
664
665
665
```scala
@@ -694,7 +694,7 @@ With `extension (p: Pizza)` we say that we want to make the methods available on
0 commit comments