Don’t use this syntax for defining lambdas. It’s long, ugly and inflexible.
A related point is in general don’t specify the types of variables unless you are first assigning it to
null. It’s unnecessary and in this particular case this one lambda forcing the types like this could add minutes to the amount of time it takes OH to load and parse these few lines of code. Instead let Rules DSL figure out the types on its own at runtime.
Constants (like c1-c9) should be declared as
Finally, when defining a lambda in this way, the last line will determine the type and the value returned by the lambda. If the last line of the lambda returns
void the lambda will be defined as a procedure. But this also means you don’t need to save a variable for your calculation. Just make the calculation be the last line.
val heatIndex = [ Number T, Number H |
val c1 = -8.78469475556
val c2 = 1.61139411
val c3 = 2.33854883889
val c4 = -0.14611605
val c5 = -0.012308094
val c6 = -0.0164248277778
val c7 = 0.002211732
val c8 = 0.00072546
val c9 = -0.000003582
c1 + c2*T + c3*H + c4*T*H + c5*(T*T) + c6*(H*H) + c7*((T*T)*H) + c8*(T*(H*H)) + c9*((T*T)*(H*H))
Not only will that do exactly the same as the original, it will load and parse way faster and in most cases work better at runtime too.