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/derivation.md
+24-11Lines changed: 24 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -31,43 +31,56 @@ More formally, for a class/trait/object/enum `DerivingType derives TC`, the foll
31
31
```scala
32
32
givenTC[DerivingType] =TC.derived
33
33
```
34
-
* if `DerivingType` has type parameters `[T_1, ... T_N]`
34
+
* if `DerivingType` has type parameters `[T_1, ..., T_N]`
35
35
```scala
36
-
given [T_1:TC, ... T_N:TC]:TC[DerivingType[T_1, ... T_N]] =TC.derived
36
+
given [T_1:TC, ... T_N:TC]:TC[DerivingType[T_1, ...,T_N]] =TC.derived
37
37
```
38
38
39
39
`TC.derived` should be an expression that conforms to the expected type `TC[DerivingType]`, potentially elaborated using term and/or type inference.
40
40
41
-
**Note:**`TC.derived` is a normal method call, therefore if there are multiple definitions of `TC.derived`, overloading resolution applies.
41
+
**Note:**`TC.derived` is a normal access, therefore if there are multiple definitions of `TC.derived`, overloading resolution applies.
42
42
43
-
**Note:**`TC.derived` can be used manually, for example to implement `Ordering` for `Option`:
43
+
**Note:**`TC.derived` can be used manually, this is useful when you do not have control over the definition. For example we can implement `Ordering` for `Option`s like so:
44
44
45
45
```scala
46
46
given [T:Ordering]:Ordering[Option[T]] =Ordering.derived
47
47
```
48
48
49
-
### `Mirror`
49
+
It is discouraged to use `derived` if you can use a `derives` clause instead.
50
+
51
+
#### CanEqual
52
+
53
+
With `DerivingType[T_1, ..., T_N] derives CanEqual`, the following instance is created:
0 commit comments