Extension Methods moving slowly SIP-ward

Mark "Justin" Waks
1 min readMar 18, 2019

--

Not quite there yet (this is basically a discussion before the formal discussion before a SIP), but the new Extension Method syntax is now being discussed on the Scala Contributors forum.

I’ve mentioned this one before: it’s basically the replacement for the main use case of implicit classes in Scala 2. Instead of playing games with implicits, we get new first-class syntax for extension methods in Scala. The syntax looks like:

def (x: String) < (y: String)

to add a new < operator to String. Basically, you can put a single-parameter list before the name of a method; that identifies the type that this method extends.

The new syntax looked a little weird to me when it was first proposed, but I’ve gradually become strongly in favor of it — I think it’s a really clear way of defining the extension method: both readable and sufficiently different so that you can easily distinguish it from ordinary methods.

Anyway, if you’re interested in the topic, check out the linked discussion, the [Dottydoc](https://dotty.epfl.ch/docs/reference/contextual/extension-methods.html), and [the PR where this got hashed out in detail](https://github.com/lampepfl/dotty/pull/5114) for more information…

--

--

Mark "Justin" Waks
Mark "Justin" Waks

Written by Mark "Justin" Waks

Lifelong programmer and software architect, specializing in online social tools and (nowadays) Scala. Architect of Querki (“leading the small data revolution”).

No responses yet