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
quantitywrapperevery unit have?
no. whatever do, 3.0 m parsed (3.0).m, there must exist method m on double (possibly through implicit conversion).
Comments
Post a Comment