View Single Post
Old 01-06-2023, 11:05 AM   #455
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,773
Karma: 7029857
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by chaley View Post
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.
chaley is offline   Reply With Quote