@@ -101,16 +101,16 @@ As in the previous example of Monoids, [`extension` methods](extension-methods.m
101101
102102``` scala
103103trait 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 ]
106106```
107107
108108The instance of ` Functor ` for ` List ` now becomes:
109109
110110``` scala
111111given 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 ] =
114114 xs.map(f) // List already has a `map` method
115115
116116```
@@ -143,12 +143,12 @@ trait Monad[F[_]] extends Functor[F]:
143143 /** The unit value for a monad */
144144 def pure [A ](x : A ): F [A ]
145145
146- extension [A , B ](x : F [A ])
146+ extension [A ](x : F [A ])
147147 /** The fundamental composition operation */
148- def flatMap (f : A => F [B ]): F [B ]
148+ def flatMap [ B ] (f : A => F [B ]): F [B ]
149149
150150 /** 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))
152152
153153end Monad
154154```
@@ -161,8 +161,8 @@ A `List` can be turned into a monad via this `given` instance:
161161given listMonad : Monad [List ] with
162162 def pure [A ](x : A ): List [A ] =
163163 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 ] =
166166 xs.flatMap(f) // rely on the existing `flatMap` method of `List`
167167```
168168
@@ -178,8 +178,8 @@ it explicitly.
178178given optionMonad : Monad [Option ] with
179179 def pure [A ](x : A ): Option [A ] =
180180 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
183183 case Some (x) => f(x)
184184 case None => None
185185```
@@ -227,8 +227,8 @@ given configDependentMonad: Monad[ConfigDependent] with
227227 def pure [A ](x : A ): ConfigDependent [A ] =
228228 config => x
229229
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 ] =
232232 config => f(x(config))(config)
233233
234234end configDependentMonad
@@ -248,8 +248,8 @@ given configDependentMonad: Monad[[Result] =>> Config => Result] with
248248 def pure [A ](x : A ): Config => A =
249249 config => x
250250
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 =
253253 config => f(x(config))(config)
254254
255255end configDependentMonad
@@ -263,8 +263,8 @@ given readerMonad[Ctx]: Monad[[X] =>> Ctx => X] with
263263 def pure [A ](x : A ): Ctx => A =
264264 ctx => x
265265
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 =
268268 ctx => f(x(ctx))(ctx)
269269
270270end readerMonad
0 commit comments