go-units
go-units copied to clipboard
Question: Is there a way to separate out a specific type of unit?
For example, if I wanted to be more constrained about the specific type of unit I wanted:
func MakeComputation(value float64, temp units.Temperature) {
...
}
In this particular example, unit.Temperature
would refer to any of unit.Celsius
, unit.Fahrenheit
, or unit.Kelvin
. Is there a way to make this slightly more specific like this?
I'm not sure if I understand the question or requirement sorry @jwir3, I should think if you're writing your own function, you can absolutely enforce any specific type on it?
func MakeComputation(value float64, temp units.Celcius) {
...
}
You could even write a generic function in later Go versions...
func MakeComputation[T units.Temperature](value float64, unit T) {
...
}
Can you perhaps further expand/explain your requirement?