Skip to content

Commit 46290f9

Browse files
Merge pull request #10869 from ayushworks/patch-1
Update type-classes.md
2 parents c1f36f4 + dca2a57 commit 46290f9

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

docs/docs/reference/contextual/derivation.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ trait Eq[T] {
259259
}
260260

261261
object Eq {
262-
given Eq[Int] {
262+
263+
given Eq[Int] with {
263264
def eqv(x: Int, y: Int) = x == y
264265
}
265266

docs/docs/reference/contextual/type-classes.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ trait Monoid[T] extends SemiGroup[T]:
2626
An implementation of this `Monoid` type class for the type `String` can be the following:
2727

2828
```scala
29-
given Monoid[String]:
29+
given Monoid[String] with
3030
extension (x: String) def combine (y: String): String = x.concat(y)
3131
def unit: String = ""
3232
```
3333

3434
Whereas for the type `Int` one could write the following:
3535

3636
```scala
37-
given Monoid[Int]:
37+
given Monoid[Int] with
3838
extension (x: Int) def combine (y: Int): Int = x + y
3939
def unit: Int = 0
4040
```
@@ -76,9 +76,9 @@ Which could read as follows: "A `Functor` for the type constructor `F[_]` repres
7676
This way, we could define an instance of `Functor` for the `List` type:
7777

7878
```scala
79-
given Functor[List]:
79+
given Functor[List] with
8080
def map[A, B](x: List[A], f: A => B): List[B] =
81-
x.map(f) // List already has a `map` method
81+
x.map(f) // List already has a `map` method
8282
```
8383

8484
With this `given` instance in scope, everywhere a `Functor` is expected, the compiler will accept a `List` to be used.
@@ -108,11 +108,10 @@ trait Functor[F[_]]:
108108
The instance of `Functor` for `List` now becomes:
109109

110110
```scala
111-
given Functor[List]:
111+
given Functor[List] with
112112
extension [A, B](xs: List[A])
113113
def map(f: A => B): List[B] =
114114
xs.map(f) // List already has a `map` method
115-
116115
```
117116

118117
It simplifies the `assertTransformation` method:

0 commit comments

Comments
 (0)