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 @propensive
This goes for OOP inheritance too. If you respect the method's contravariance for input, covariance for output, an overridden method can have a more specific signature than the method it overrides. There are non-obvious limits to extensions, which makes them "not a method".
1 reply 0 retweets 1 like
I read this after my reply, but I think we're talking about the same thing. :)
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.