unit
unit copied to clipboard
Un-specialcase Temperature
All converted units with the exception of temperatures can be easily converted using multiply, like this:
in := (Meter * 5).Inches()
It would be nice if temperature could too be used in this fashion, removing the need for special casing in the lib.
Some failed attempt exists in branch "temp" in https://github.com/martinlindhe/unit/commit/8478d54352c96018ec89e168039585f4c88b3891
I like the way you've done your temperature logic better. I think you should move the rest of the code in that direction. I think it gives consumers of your code better readability. If I have a method that calculates the area of a box I could make the method signature look something like this (This assumes all of your underlying units are SI units)
func AreaOfBox(l Length, w Length, h Length) Volume {
return Volume(l * w * h)
}
func FromMeter(l float64) Length {
return Length(l)
}
assertFloatEqual(t, 2*6*5, AreaOfBox(FromMeter(2), FromMeter(6), FromMeter(5)).CubicMeters())