Skip to content

Commit 5a29693

Browse files
committed
Responding to more comments
1 parent f0531f6 commit 5a29693

File tree

3 files changed

+39
-20
lines changed

3 files changed

+39
-20
lines changed

Diff for: _overviews/scala3-book/collections-methods.md

+15-17
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ a.takeRight(2) // List(40, 10)
5151
```
5252

5353

54-
### Lambdas and HOFs
54+
### Higher-order functions and lambdas
5555

56-
Next, we’ll show some commonly used higher-order functions (HOFs) that accept _lambda_ methods. To get started, here are several variations of the lambda syntax, starting with the longest form, working in steps towards the most concise form:
56+
Next, we’ll show some commonly used higher-order functions (HOFs) that accept lambdas (anonymous functions). To get started, here are several variations of the lambda syntax, starting with the longest form, working in steps towards the most concise form:
5757

5858
```scala
5959
// these functions are all equivalent and return
@@ -171,6 +171,19 @@ scala> val shortNames = names.filter(_.length <= 4)
171171
shortNames: List[String] = List(adam)
172172
```
173173

174+
A great thing about the functional methods on collections is that you can chain them together to solve problems. For instance, this example shows how to chain `filter` and `map`:
175+
176+
```scala
177+
oneToTen.filter(_ < 4).map(_ * 10)
178+
```
179+
180+
The REPL shows the result:
181+
182+
```scala
183+
scala> oneToTen.filter(_ < 4).map(_ * 10)
184+
val res1: List[Int] = List(10, 20, 30)
185+
```
186+
174187

175188

176189
## `foreach`
@@ -185,21 +198,6 @@ chris
185198
david
186199
```
187200

188-
A great thing about the functional methods on the collections is that you can chain them together to solve problems. For example, this is one way to print the first three elements from `oneToTen`:
189-
190-
```scala
191-
oneToTen.filter(_ < 4).foreach(println)
192-
```
193-
194-
The REPL shows the result:
195-
196-
```scala
197-
scala> oneToTen.filter(_ < 4).foreach(println)
198-
1
199-
2
200-
3
201-
```
202-
203201

204202

205203
## `head`

Diff for: _overviews/scala3-book/domain-modeling-fp.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ This chapter provides an introduction to domain modeling using functional progra
1414
- Case classes
1515
- Traits
1616

17+
>If you’re not familiar with algebraic data types (ADTs) and their generalized version (GADTs), you may want to read the [Algebraic Data Types][adts] section before reading this section.
18+
19+
1720

1821
## Introduction
1922

@@ -156,7 +159,7 @@ def crustPrice(s: CrustSize, t: CrustType): Double =
156159
case (Large, Regular) => 0.75
157160
case (Large, Thick) => 1.00
158161
```
159-
To compute the price of the crust we simultanously pattern match on both the size and the type of the crust.
162+
To compute the price of the crust we simultaneously pattern match on both the size and the type of the crust.
160163

161164
> An important point about all functions shown above is that they are *pure functions*: they do not mutate any data or have other side-effects (like throwing exceptions or writing to a file). All they do is simply receive values and compute the result.
162165
@@ -174,7 +177,11 @@ These different solutions are shown in the remainder of this section.
174177

175178
### Companion Object
176179

177-
A first approach is to define the behavior — the functions — in a companion object. With this approach, in addition to the enumeration or case class you also define an equally named companion object that contains the behavior.
180+
A first approach is to define the behavior — the functions — in a companion object.
181+
182+
>As discussed in the Domain Modeling [Tools section][modeling-tools], a _companion object_ is an `object` that has the same name as a class, and is declared in the same file as the class.
183+
184+
With this approach, in addition to the enumeration or case class you also define an equally named companion object that contains the behavior.
178185

179186
```scala
180187
case class Pizza(
@@ -410,3 +417,7 @@ Then, to model the behavior define functions that operate on values of your data
410417
- You can use a modular programming style, separating interface and implementation
411418
- You can use a “functional objects” approach and store the methods on the defined data type
412419
- You can use extension methods to equip your data model with functionality
420+
421+
422+
[adts]: {% link _overviews/scala3-book/types-adts-gadts.md %}
423+
[modeling-tools]: {% link _overviews/scala3-book/domain-modeling-tools.md %}

Diff for: _overviews/scala3-book/scala-for-javascript-devs.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,17 @@ Many uses of strings are similar in JavaScript and Scala, though Scala only uses
196196
</tr>
197197
</table>
198198

199-
Scala lets you create multiline strings, which also support interpolation:
199+
JavaScript lets you create multiline strings with backticks, and supports interpolation:
200+
201+
```javascript
202+
let name = "joe";
203+
let str = `
204+
Hello, ${name}.
205+
This is a multiline string.
206+
`;
207+
```
208+
209+
Scala lets you create multiline strings with string interpolation:
200210

201211
```scala
202212
val name = "Martin Odersky"

0 commit comments

Comments
 (0)