import itertools


def is_doc2vec_corpus(obj):
    """Check whether `obj` is a corpus.

    Parameters
    ----------
    obj : object
        Something `iterable of iterable` that contains str.

    Return
    ------
    (bool, object)
        Pair of (is_corpus, `obj`), is_corpus True if `obj` is corpus.

    Warnings
    --------
    An "empty" corpus (empty input sequence) is ambiguous, so in this case
    the result is forcefully defined as (False, `obj`).
    """
    try:
        if hasattr(obj, 'next') or hasattr(obj, '__next__'):
            # the input is an iterator object, meaning once we call next()
            # that element could be gone forever. we must be careful to put
            # whatever we retrieve back again
            doc1 = next(obj)
            obj = itertools.chain([doc1], obj)
        else:
            doc1 = next(iter(obj))  # empty corpus is resolved to False here

        # Document is represented by a list of words, not a string
        if type(doc1) is str:
            return False, obj

        # if obj is not list of strings, it resolves to False here
        string = next(iter(doc1))

        if type(string) is not str:
            return False, obj
    except Exception:
        return False, obj
    return True, obj