Source code for ds_common_placeholder_py_lib.functions.values
"""
**File:** ``functions/values.py``
**Region:** ``ds-common-placeholder-py-lib``
Description
-----------
``coalesce``: the first argument that is not missing.
"""
from __future__ import annotations
from typing import TYPE_CHECKING, Any
from ..errors import MissingValue
if TYPE_CHECKING:
from collections.abc import Callable
[docs]
def coalesce(args: list[Callable[[], Any]]) -> Any:
"""Return the first argument that has a value, reading them left to
right and stopping there. Only a missing value (no such path, ``null``,
blank) moves on; any other error is raised.
Raises:
MissingValue: If every argument is missing.
"""
for arg in args:
try:
return arg()
except MissingValue:
continue
raise MissingValue