When parsing data like strings into enumeration values, developers often face repetitive and time-consuming code patterns. Repeatedly evaluating the same expression across multiple cases can clutter code and reduce efficiency.
A streamlined "switch-like" function could significantly improve this process by eliminating redundancy and enhancing scalability. Evaluate the expression once and match it against multiple cases.
This feature would make parsing operations faster, cleaner, and more intuitive, ideal for scenarios where large mappings or enums are involved.
Example now:
if trim(toUpperCase($BillingDetails/Country)) = 'SPAIN' or trim(toUpperCase($BillingDetails/Country)) = 'ESPAÑA' then
Countries.ISO2.ES
else if trim(toUpperCase($BillingDetails/Country)) = 'PORTUGAL' then
Countries.ISO2.PT
else if trim(toUpperCase($BillingDetails/Country)) = 'ITALY' then
Countries.ISO2.IT
else if trim(toUpperCase($BillingDetails/Country)) = 'SWEDEN' then
Countries.ISO2.SE
else if trim(toUpperCase($BillingDetails/Country)) = 'NORWAY' then
Countries.ISO2.NO
else
empty
Example with switch function:
switch(trim(toUpperCase($BillingDetails/Country)))
case 'SPAIN':
Countries.ISO2.ES
case 'ESPAÑA':
Countries.ISO2.ES
case 'PORTUGAL':
Countries.ISO2.PT
case 'ITALY':
Countries.ISO2.IT
case 'SWEDEN':
Countries.ISO2.SE
case 'NORWAY':
Countries.ISO2.NO
default:
empty
end switch
Yes please, this is -much- easier to read!