def unique(seq, key=None, return_as=None):
    """Unique the seq and keep the order.

    Instead of the slow way:
        `lambda seq: (x for index, x in enumerate(seq) if seq.index(x)==index)`

    :param seq: raw sequence.
    :param return_as: generator for default, or list / set / str...

    >>> from torequests.utils import unique
    >>> a = [1,2,3,4,2,3,4]
    >>> unique(a)
    <generator object unique.<locals>.<genexpr> at 0x05720EA0>
    >>> unique(a, str)
    '1234'
    >>> unique(a, list)
    [1, 2, 3, 4]
    """
    seen = set()
    add = seen.add
    if key:
        generator = (x for x in seq if key(x) not in seen and not add(key(x)))
    else:
        generator = (x for x in seq if x not in seen and not add(x))
    if return_as:
        if return_as == str:
            return "".join(map(str, generator))
        else:
            return return_as(generator)
    else:
        # python2 not support yield from
        return generator