If I have this pure function:
func PureFunction(x int) string {
switch x {
case 0:
return "String zero"
case 4:
return "String four"
default:
return "Default string"
}
}
and want to use it in a constant declaration like this:
const str1 = PureFunction(0)
const str1 = PureFunction(4)
const str1 = PureFunction(5)
I get the errors:
PureFunction(0) (value of type string) is not constant
PureFunction(4) (value of type string) is not constant
PureFunction(5) (value of type string) is not constant
In theory the compiler should be able to see that these values are constant.
Is there a way to do something like this? Like defining the function as pure or some other trick to help the compiler?