import itertools


def repeat(value, times=-1):
    """:yaql:repeat

    Returns collection with value repeated.

    :signature: value.repeat(times => -1)
    :receiverArg value: value to be repeated
    :argType value: any
    :arg times: how many times repeat value. -1 by default, which means that
        returned value will be an iterator to the endless sequence of values
    :argType times: int
    :returnType: iterable

    .. code::

        yaql> 1.repeat(2)
        [1, 1]
        yaql> 1.repeat().take(3)
        [1, 1, 1]
    """
    if times < 0:
        return itertools.repeat(value)
    else:
        return itertools.repeat(value, times)