Scala DSL: How to omit parentheses from apply call? -


i wrote small library units of measure (yes, use squants this, need features squants not provide). unit class unitofmeasure , quantity, i.e., number , unit, quantity.

suppose defined m unitofmeasure, want write like:

val q = 3.0 m 

i created class quantitywrapper in package object so:

implicit class quantitywrapper[t](value: t)(implicit num: numeric[t]) {    def apply(unit: unitofmeasure[t]): quantity[t] =     quantity(value, unit) } 

so can do:

val q = 3.0(m) 

because 3.0 implicitly converted quantitywrapper[double] , m defined unitofmeasure[double].

but want able omit parentheses. possible without defining methods in quantitywrapper every unit have?

is possible without defining methods in quantitywrapper every unit have?

no. whatever do, 3.0 m parsed (3.0).m, there must exist method m on double (possibly through implicit conversion).


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -