Story : How to run script faster - HiStructClient/femcad-doc GitHub Wiki
You can increase the speed of calculation by the following syntax which ensures that only array values are furter used, unlike complete formulas defining the values, like in standard cases:
Fcs.Types.Array(array).ItemValues
I was wondering, many times, if there is a difference in decision which variant is used made by ternary operators or picking an item from an array. In case there are more than just two variants (let's take 4 in this case) the syntax of ternary operator becomes quote complicated:
value := (variant == 0)?(varA):((variant == 1)?(varB):((variant == 2.........)))
A bit more comprehensive is the array "picker":
value := [varA, varB, varC, varD][variant]
But there is a danger that each of the array items is time consuming and because whole array is evaluated first and particular variant is used further afterwards, this may be too "expensive". Also, there might be a situation when some of the array item is even not evaluable. In this our code fails.
Thanks God (and our FemCad guru), we have one more option which is both fast enough and easy to read. An array of lambdas. The above examples could go like this:
varArray := [(i => varA), (i => varB), (i => varC), (i => varD)]
value := varArray[variant](0)