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: docs/docs/reference/contextual/import-delegate.md
+20-22Lines changed: 20 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,12 +3,12 @@ layout: doc-page
3
3
title: "Import Given"
4
4
---
5
5
6
-
A special form of import selector is used to import given instances. Example:
6
+
A special form of import wildcard selector is used to import given instances. Example:
7
7
```scala
8
8
objectA {
9
9
classTC
10
-
giventc asTC
11
-
deff where TC=???
10
+
giventc:TC
11
+
deff(givenTC)=???
12
12
}
13
13
objectB {
14
14
importA._
@@ -19,16 +19,16 @@ In the code above, the `import A._` clause of object `B` will import all members
19
19
of `A`_except_ the given instance `tc`. Conversely, the second import `import A.given` will import _only_ that given instance.
20
20
The two import clauses can also be merged into one:
21
21
```scala
22
-
objectB:
22
+
objectB
23
23
importA.{given, _}
24
24
```
25
25
26
-
Generally, a normal import selector brings definitions other than given instances into scope whereas a `given`import selector brings only given instances into scope.
26
+
Generally, a normal wildcard selector `_`brings all definitions other than given instances into scope whereas a `given` selector brings all given instances into scope.
27
27
28
28
There are two main benefits arising from these rules:
29
29
30
30
- It is made clearer where givens in scope are coming from.
31
-
In particular, it is not possible to hide imported givens in a long list of regular imports.
31
+
In particular, it is not possible to hide imported givens in a long list of regular wildcard imports.
32
32
- It enables importing all givens
33
33
without importing anything else. This is particularly important since givens
34
34
can be anonymous, so the usual recourse of using named imports is not
@@ -39,32 +39,32 @@ There are two main benefits arising from these rules:
39
39
Since givens can be anonymous it is not always practical to import them by their name, and wildcard imports are typically used instead. By-type imports provide a more specific alternative to wildcard imports, which makes it clearer what is imported. Example:
40
40
41
41
```scala
42
-
importA.{givenasTC}
42
+
importA.{givenTC}
43
43
```
44
44
This imports any given in `A` that has a type which conforms to `TC`. Importing givens of several types `T1,...,Tn`
45
45
is expressed by multiple `given` selectors.
46
46
```
47
-
import A.{given as T1, ..., given as Tn}
47
+
import A.{given T1, ..., given Tn}
48
48
```
49
49
Importing all given instances of a parameterized type is expressed by wildcard arguments.
0 commit comments