The obvious benefit of extension methods is that they allow us to append methods to a type *after* it has been defined. But an undervalued advantage is that they append methods to *types*, with all the flexibility Scala gives us to specify those types precisely or generally.
-
Show this thread
-
Replying to @propensive
You're right, except when it doesn't work. One common gotcha is that class methods have a higher priority than extension methods. And we can't specify priorities for extensions defined by 2 different parties.
1 reply 0 retweets 3 likes -
Replying to @alexelcu @propensive
E.g. if you define an opaque type + flatMap is very different from a class + a flatMap method. The later can specify a flatMap method with a more flexible signature than Monad.flatMap, whereas the former cannot do it. Kind of pisses me off
2 replies 0 retweets 1 like -
Replying to @alexelcu
I imagine there would be an unacceptable performance hit if extension methods were considered as potentially higher-priority than class methods for every call, but there might be ways to optimize this.
1 reply 0 retweets 0 likes
I can see the annoyance, though it might be surprising if calling `flatMap` on a value whose type is able to infer an extension method did something different from calling `flatMap` on the same value when its in a generic context and the extension can't be used.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.