martinlindhe/unit

Un-specialcase Temperature

Opened this issue · 1 comments

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
8478d54

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())