What is the shortest notation for defining a statement as an alias of a method in Scala?

Given the generic register method below, I would like to define the := operator as a symbolic alias.

 def register[Prop <: Property[_]](prop: Prop): Prop @inline final def :=[Prop <: Property[_]] = register[Prop] _ 

Initially, I wanted to write something like this:

 val := = register _ 

But that gives me the signature of the Nothing => Nothing function. My next attempt was to parameterize it with the Prop type, but this apparently only works if I def , which can take type parameters and pass them forward.

Ideally, I would like to omit the @inline annotation, but I'm not sure what kind of object code the Scala compiler makes from it.

My most important goal is to not use the := method to duplicate all parts of the register method signature except the name, and then just let the former delegate to the latter.

+7
source share
3 answers
 def :=[Prop <: Property[_]](prop: Prop) = register(prop) 

must work.

+2
source

I do not believe that there is any way to achieve what you need (basically what alias gives you in Ruby) in Scala, as it stands now. The autoproxy plugin is an attempt to solve this problem, but it is not yet ready for use in production due to various problems with code generation in the plugin compiler.

+1
source

You can do it:

 def := : Prop => Prop = register 

So basically here you are defining a function of type (Prop => Prop), which simply refers to another function.

+1
source

All Articles