from typing import Iterable
from typing import Union
from typing import Any
from typing import Mapping


def reduce(values: Iterable) -> Union[Iterable, Any]:
    """ Reduce an iterable to a scalar if length is 1. Returns None if iterable
        is empty. """

    try:
        while isinstance(values, Iterable) and not isinstance(values, (Mapping, str)):
            values = list(values)
            if len(values) <= 1:
                values = values[0]
            else:
                break

        return values

    except IndexError:
        return None