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] _
Originally I wanted to write something like this:
val := = register _
But that gives me the function signature Nothing => Nothing
. My next attempt was to parameterize it with the type Prop
but that apparently works only if I make it a def
, which can take type parameters and pass them onwards.
Ideally I would like to omit the @inline
annotation but I am not sure what object code the Scala compiler makes out of it.
Most important my goal is it not to have the :=
method duplicate all parts of the register
method's signature except for the name and then simply let the former delegate to the latter.
def :=[Prop <: Property[_]](prop: Prop) = register(prop)
should work.
I don't believe that there's any way to achieve what you're after (basically what alias
gives you in Ruby) in Scala as it currently stands. The autoproxy plugin is an attempt to address this kind of problem, but it's not really ready for production use yet due to various issues with generating code in compiler plugins.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With