[ad_1]
However, it seems you could just as easily define the extension next to the given:
That would mean requiring to define the extension for each instance over and over again; although that is still the case in the provided example.
A better example would be this:
trait Functor[F[_]]:
extension [A](fa: F[A])
def map[B](f: A => B): F[B]
final def as[B](b: B): F[A] = fa.map(_ => b)
end Functor
object List:
given Functor[List] with:
extension [A](la: List[A])
override def map[B](f: A => B): List[B] =
...
end List
List(1, 2, 3).as("Foo")
The as
extension method would be available out of the box.
Although, I personally think most libraries will continue to provide the extensions on a different syntax
object to be imported.
[ad_2]