from typing import List
from typing import Optional
from typing import Callable
from typing import Any


def to_value(row: List, transformer: Optional[Callable] = None) -> Any:
    """Convert a given list of values into a scalar value or tuple.

    If the given list contains a single element that element is returned.
    Otherwise, a tuple of the values in the list is returned.

    The optional tranformer is applied to all list values individually.

    Parameters
    ----------
    row: list
        List of column values for row in a dataset.

    Returns
    -------
    any
    """
    row = row if transformer is None else list(map(transformer, row))
    return row[0] if len(row) == 1 else tuple(row)