Skip to content

Commit 001e9cf

Browse files
authored
Merge pull request #12552 from IvannKurchenko/patch-1
Added Mirror import statement in code examples.
2 parents 86965af + c400c37 commit 001e9cf

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

docs/docs/reference/contextual/derivation.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ signature and implementation of a `derived` method for a type class `TC[_]` are
142142
following form,
143143

144144
```scala
145+
import scala.deriving.Mirror
146+
145147
def derived[T](using Mirror.Of[T]): TC[T] = ...
146148
```
147149

@@ -176,6 +178,8 @@ we need to implement a method `Eq.derived` on the companion object of `Eq` that
176178
a `Mirror[T]`. Here is a possible implementation,
177179

178180
```scala
181+
import scala.deriving.Mirror
182+
179183
inline given derived[T](using m: Mirror.Of[T]): Eq[T] =
180184
val elemInstances = summonAll[m.MirroredElemTypes] // (1)
181185
inline m match // (2)
@@ -209,6 +213,8 @@ values are of the same subtype of the ADT (3) and then, if they are, to further
209213
instance for the appropriate ADT subtype using the auxiliary method `check` (4).
210214

211215
```scala
216+
import scala.deriving.Mirror
217+
212218
def eqSum[T](s: Mirror.SumOf[T], elems: List[Eq[_]]): Eq[T] =
213219
new Eq[T]:
214220
def eqv(x: T, y: T): Boolean =
@@ -220,6 +226,8 @@ In the product case, `eqProduct` we test the runtime values of the arguments to
220226
on the `Eq` instances for the fields of the data type (5),
221227

222228
```scala
229+
import scala.deriving.Mirror
230+
223231
def eqProduct[T](p: Mirror.ProductOf[T], elems: List[Eq[_]]): Eq[T] =
224232
new Eq[T]:
225233
def eqv(x: T, y: T): Boolean =

0 commit comments

Comments
 (0)