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/ca-context-bounds.md
+3-4Lines changed: 3 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -13,14 +13,13 @@ next-page: ca-given-imports
13
13
- TODO: define "synthesized" and "synthesized arguments"
14
14
{% endcomment %}
15
15
16
-
17
-
In many situations the name of a *context parameter* doesn’t have to be mentioned explicitly, since it’s only used in synthesized arguments for other context parameters.
16
+
In many situations the name of a _context parameter_ doesn’t have to be mentioned explicitly, since it’s only used in synthesized arguments for other context parameters.
18
17
In that case you don’t have to define a parameter name, and can just provide the parameter type.
19
18
20
19
21
20
## Background
22
21
23
-
For example, this `maximum` method takes a *context parameter* of type `Ord`, only to pass it on as an argument to `max`:
22
+
For example, this `maximum` method takes a _context parameter_ of type `Ord`, only to pass it on as an argument to `max`:
24
23
25
24
```scala
26
25
defmaximum[T](xs: List[A])(usingord: Ord[A]):A=
@@ -37,7 +36,7 @@ def maximum[T](xs: List[A])(using Ord[A]): A =
37
36
38
37
## Context bounds
39
38
40
-
Given that background, a *context bound* is a shorthand syntax for expressing the pattern of, “a context parameter that depends on a type parameter.”
39
+
Given that background, a _context bound_ is a shorthand syntax for expressing the pattern of, “a context parameter that depends on a type parameter.”
41
40
42
41
Using a context bound, the `maximum` method can be written like this:
LATER: note that methods like `+`, `++`, etc., are aliases for other methods
15
14
LATER: add links to the Scaladoc for the major types shown here
@@ -29,19 +28,38 @@ When you need more flexibility, see these pages at the end of this section for m
29
28
30
29
Looking at Scala collections from a high level, there are three main categories to choose from:
31
30
32
-
- Sequences
33
-
- Maps
34
-
- Sets
31
+
-**Sequences** are a linear collection of elements and may be _indexed_ (like an array) or _linear_ (like a linked list)
32
+
-**Maps** contain a collection of key/value pairs, like a Java `Map`, Python dictionary, or Ruby `Hash`
33
+
-**Sets** are an unordered sequence of unique elements
35
34
36
-
A _sequence_ is a linear collection of elements and may be _indexed_ (like an array) or _linear_ (like a linked list).
37
-
A _map_ contains a collection of key/value pairs, like a Java `Map`, Python dictionary, or Ruby `Hash`.
38
-
A _set_ is an unordered sequence of unique elements.
39
35
All of those are basic types, and have subtypes for specific purposes, such as concurrency, caching, and streaming.
36
+
In addition to those three main categories, there are other useful collection types, including ranges, stacks, and queues.
40
37
41
-
In addition to these three main categories, there are other useful collection types, including ranges, stacks, and queues.
42
-
Ranges are demonstrated later in this section.
43
38
44
-
The following sections introduce the common types you’ll use on a regular basis.
39
+
### Collections hierarchy
40
+
41
+
As a brief overview, the next three figures show the hierarchy of classes and traits in the Scala collections.
42
+
43
+
This first figure shows the collections types in package
44
+
_scala.collection_.
45
+
These are all high-level abstract classes or traits, which
46
+
generally have _immutable_ and _mutable_ implementations.
47
+
48
+
![General collection hierarchy][collections1]
49
+
50
+
This figure shows all collections in package _scala.collection.immutable_:
51
+
52
+
![Immutable collection hierarchy][collections2]
53
+
54
+
And this figure shows all collections in package _scala.collection.mutable_:
55
+
56
+
![Mutable collection hierarchy][collections3]
57
+
58
+
Having seen that detailed view of all of the collections types, the following sections introduce some of the common types you’ll use on a regular basis.
59
+
60
+
{% comment %}
61
+
NOTE: those images come from this page: https://docs.scala-lang.org/overviews/collections-2.13/overview.html
62
+
{% endcomment %}
45
63
46
64
47
65
@@ -617,3 +635,6 @@ When you need more information about specialized collections, see the following
617
635
618
636
619
637
[strict]: {% link _overviews/core/architecture-of-scala-213-collections.md %}
Copy file name to clipboardExpand all lines: _overviews/scala3-book/domain-modeling-oop.md
-3Lines changed: 0 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -171,9 +171,6 @@ Protected members are also visible to subclasses of the class.
171
171
In the following, we illustrate some advanced features of Scala and show how they can be used to structure larger software components.
172
172
The examples are adapted from the paper ["Scalable Component Abstractions"][scalable] by Martin Odersky and Matthias Zenger.
173
173
Don’t worry if you don’t understand all the details of the example; it’s primarily intended to demonstrate how to use several type features to construct larger components.
174
-
{% comment %}
175
-
TODO: I’m not sure what I added in that last sentence is accurate or helpful, but I wanted to add a note about why readers shouldn’t worry about understanding the example.
176
-
{% endcomment %}
177
174
178
175
Our goal is to define a software component with a _family of types_ that can be refined later in implementations of the component.
179
176
Concretely, the following code defines the component `SubjectObserver` as a trait with two abstract type members, `S` (for subjects) and `O` (for observers):
0 commit comments