One nice feature of Unitful is that units are callable, acting like shortcuts to uconvert. Would it be possible to add a method to units to make units callable with an equivalence? This would be helpful for shorter conversion calls.
Current:
julia> using Unitful, UnitfulEquivalences
julia> lambda = 300u"nm";
julia> uconvert(u"Hz", lambda, Spectral())
9.993081933333334e14 Hz
julia> Unitful.c/lambda |> u"Hz"
9.993081933333334e14 Hz
Proposed:
julia> lambda |> u"Hz"(Spectral())
9.993081933333334e14 Hz
This could be easily implemented by something like:
function (unit::Unit)(eq::Equivalence)
return quantity -> uconvert(u, quantity, eq)
end
The syntax is not the cleanest (suggestions welcome!), but like Unitful, it allows the quantity in question to be front and center and the latter parts of the statement being conversion arithmetic.
One nice feature of Unitful is that units are callable, acting like shortcuts to
uconvert. Would it be possible to add a method to units to make units callable with an equivalence? This would be helpful for shorter conversion calls.Current:
Proposed:
This could be easily implemented by something like:
The syntax is not the cleanest (suggestions welcome!), but like Unitful, it allows the quantity in question to be front and center and the latter parts of the statement being conversion arithmetic.