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-implied.md
+30Lines changed: 30 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,7 @@ A special form of import is used to import implied instances. Example:
8
8
objectA {
9
9
classTC
10
10
implied tc forTC
11
+
implied
11
12
deffgivenTC=???
12
13
}
13
14
objectB {
@@ -28,6 +29,35 @@ There are two main benefits arising from these rules:
28
29
instances can be anonymous, so the usual recourse of using named imports is not
29
30
practical.
30
31
32
+
### Importing By Type
33
+
34
+
Since implied instances 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:
35
+
36
+
```scala
37
+
importimpliedA.{forTC}
38
+
```
39
+
This imports any implied instance in `A` that has a type which conforms tp `TC`. There can be several bounding types following a `for` and bounding types can contain wildcards.
0 commit comments