Quote:
Originally Posted by chaley
I have wondered whether I should make a variant that combines first_non_empty() and switch(), perhaps named first_true(). It would take a list of argument pairs where each pair is a condition expression and a value expression. For each pair in order it would evaluate the condition. If True then it would evaluate the value expression and return it, otherwise try the next pair. There would be a 'none are true' value at the end, like switch().
This would be faster than either first_non_empty() or a series of ifs, and would probably be easier to read. But it would be yet another maintenance and documentation chore. It is also quite easy to do in a python template. I am still thinking about it.
|
I added the function switch_if(). It is in source now.