@@ -101,16 +101,16 @@ As in the previous example of Monoids, [`extension` methods](extension-methods.m
101
101
102
102
``` scala
103
103
trait Functor [F [_]]:
104
- extension [A , B ](x : F [A ])
105
- def map (f : A => B ): F [B ]
104
+ extension [A ](x : F [A ])
105
+ def map [ B ] (f : A => B ): F [B ]
106
106
```
107
107
108
108
The instance of ` Functor ` for ` List ` now becomes:
109
109
110
110
``` scala
111
111
given Functor [List ] with
112
- extension [A , B ](xs : List [A ])
113
- def map (f : A => B ): List [B ] =
112
+ extension [A ](xs : List [A ])
113
+ def map [ B ] (f : A => B ): List [B ] =
114
114
xs.map(f) // List already has a `map` method
115
115
116
116
```
@@ -143,12 +143,12 @@ trait Monad[F[_]] extends Functor[F]:
143
143
/** The unit value for a monad */
144
144
def pure [A ](x : A ): F [A ]
145
145
146
- extension [A , B ](x : F [A ])
146
+ extension [A ](x : F [A ])
147
147
/** The fundamental composition operation */
148
- def flatMap (f : A => F [B ]): F [B ]
148
+ def flatMap [ B ] (f : A => F [B ]): F [B ]
149
149
150
150
/** The `map` operation can now be defined in terms of `flatMap` */
151
- def map (f : A => B ) = x.flatMap(f.andThen(pure))
151
+ def map [ B ] (f : A => B ) = x.flatMap(f.andThen(pure))
152
152
153
153
end Monad
154
154
```
@@ -161,8 +161,8 @@ A `List` can be turned into a monad via this `given` instance:
161
161
given listMonad : Monad [List ] with
162
162
def pure [A ](x : A ): List [A ] =
163
163
List (x)
164
- extension [A , B ](xs : List [A ])
165
- def flatMap (f : A => List [B ]): List [B ] =
164
+ extension [A ](xs : List [A ])
165
+ def flatMap [ B ] (f : A => List [B ]): List [B ] =
166
166
xs.flatMap(f) // rely on the existing `flatMap` method of `List`
167
167
```
168
168
@@ -178,8 +178,8 @@ it explicitly.
178
178
given optionMonad : Monad [Option ] with
179
179
def pure [A ](x : A ): Option [A ] =
180
180
Option (x)
181
- extension [A , B ](xo : Option [A ])
182
- def flatMap (f : A => Option [B ]): Option [B ] = xo match
181
+ extension [A ](xo : Option [A ])
182
+ def flatMap [ B ] (f : A => Option [B ]): Option [B ] = xo match
183
183
case Some (x) => f(x)
184
184
case None => None
185
185
```
@@ -227,8 +227,8 @@ given configDependentMonad: Monad[ConfigDependent] with
227
227
def pure [A ](x : A ): ConfigDependent [A ] =
228
228
config => x
229
229
230
- extension [A , B ](x : ConfigDependent [A ])
231
- def flatMap (f : A => ConfigDependent [B ]): ConfigDependent [B ] =
230
+ extension [A ](x : ConfigDependent [A ])
231
+ def flatMap [ B ] (f : A => ConfigDependent [B ]): ConfigDependent [B ] =
232
232
config => f(x(config))(config)
233
233
234
234
end configDependentMonad
@@ -248,8 +248,8 @@ given configDependentMonad: Monad[[Result] =>> Config => Result] with
248
248
def pure [A ](x : A ): Config => A =
249
249
config => x
250
250
251
- extension [A , B ](x : Config => A )
252
- def flatMap (f : A => Config => B ): Config => B =
251
+ extension [A ](x : Config => A )
252
+ def flatMap [ B ] (f : A => Config => B ): Config => B =
253
253
config => f(x(config))(config)
254
254
255
255
end configDependentMonad
@@ -263,8 +263,8 @@ given readerMonad[Ctx]: Monad[[X] =>> Ctx => X] with
263
263
def pure [A ](x : A ): Ctx => A =
264
264
ctx => x
265
265
266
- extension [A , B ](x : Ctx => A )
267
- def flatMap (f : A => Ctx => B ): Ctx => B =
266
+ extension [A ](x : Ctx => A )
267
+ def flatMap [ B ] (f : A => Ctx => B ): Ctx => B =
268
268
ctx => f(x(ctx))(ctx)
269
269
270
270
end readerMonad
0 commit comments