first_with_value
Returns the first argument that has a truthy value. Checks each argument in order and returns the first one that is not None, False, or an empty string/collection. If all arguments are empty or falsy, returns None.
Syntax
first_with_value(value1, value2, ...)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| value1, value2, ... | any | Yes (at least one) | The values to check, in order of priority. |
Returns
Type: any
The first argument that is not None, False, an empty string, or an empty collection. Returns None if all arguments are empty or falsy.
Examples
Select the first available identifier:
first_with_value([employee_id], [email], [username], "unknown")
Returns whichever of employee_id, email, or username has a value first. Falls back to "unknown" if all three are empty.
Coalesce description fields from different sources:
first_with_value([long_description], [short_description], "No description")
Prefers the long description, falls back to the short description, and finally uses a default string.
Notes
- Numeric zero (
0) is treated as a valid value and will be returned. OnlyNone,False, empty strings, empty lists, and empty dictionaries are skipped. - Boolean
Falseis explicitly skipped and is not treated as numeric zero. - This function is similar to the SQL
COALESCEfunction.
Comments
0 comments
Please sign in to leave a comment.