from typing import Mapping


def update(to_update, update_with):
    """
    Recursively update a dictionary with another.

    :param dict to_update: Dictionary to update.
    :param dict update_with: Dictionary to update with.

    :return: The first dictionary recursively updated by the second.
    :rtype: dict
    """
    for key, value in update_with.items():
        if isinstance(value, Mapping):
            to_update[key] = update(
                to_update.get(key, type(value)()),
                value,
            )
        else:
            to_update[key] = value

    return to_update