from typing import Any


def _flatten_list(val: Any, *, delimiter: str = "|", force: bool = False) -> Any:
    """
    Flattens list types to strings.
    By default, only list[string] is flattened to a single string.
    The `force` parameter allows flattening of other inner types like numerics to a string.
    A list of length 1 becomes a string.
    A list with length longer than 1 has its elements concatenated with the specified `delimiter`.
    Non-list types are passed through directly.
    Intended to be applied using `applymap` to a DataFrame created from a Tamr Dataset,
    or to a pandas Series using `apply`.

    Args:
        val: value to convert
        delimiter: string to use as delimiter for concatenating lists
        force: if True, will force non-string inner types to string

    Returns:
        string or original value
    """
    if isinstance(val, list):
        if force:
            # convert inner values to strings.  f-strings are faster than str()
            return delimiter.join(f"{i}" for i in filter(None, val))
        else:
            return delimiter.join(filter(None, val))
    else:
        return val