@@ -26,15 +26,15 @@ trait Monoid[T] extends SemiGroup[T]:
26
26
An implementation of this ` Monoid ` type class for the type ` String ` can be the following:
27
27
28
28
``` scala
29
- given Monoid [String ]:
29
+ given Monoid [String ] with
30
30
extension (x : String ) def combine (y : String ): String = x.concat(y)
31
31
def unit : String = " "
32
32
```
33
33
34
34
Whereas for the type ` Int ` one could write the following:
35
35
36
36
``` scala
37
- given Monoid [Int ]:
37
+ given Monoid [Int ] with
38
38
extension (x : Int ) def combine (y : Int ): Int = x + y
39
39
def unit : Int = 0
40
40
```
@@ -76,9 +76,9 @@ Which could read as follows: "A `Functor` for the type constructor `F[_]` repres
76
76
This way, we could define an instance of ` Functor ` for the ` List ` type:
77
77
78
78
``` scala
79
- given Functor [List ]:
79
+ given Functor [List ] with
80
80
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
82
82
```
83
83
84
84
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[_]]:
108
108
The instance of ` Functor ` for ` List ` now becomes:
109
109
110
110
``` scala
111
- given Functor [List ]:
111
+ given Functor [List ] with
112
112
extension [A , B ](xs : List [A ])
113
113
def map (f : A => B ): List [B ] =
114
114
xs.map(f) // List already has a `map` method
115
-
116
115
```
117
116
118
117
It simplifies the ` assertTransformation ` method:
0 commit comments