def _to_original(sequence, result):
    """ Cast result into the same type

    >>> _to_original([], ())
    []

    >>> _to_original((), [])
    ()

    """

    if isinstance(sequence, tuple):
        return tuple(result)
    if isinstance(sequence, list):
        return list(result)

    return result