Exemplo n.º 1
0
def iterate_(func, times, value):
    """Use toolz iterate function to actually iterate

    >>> assert iterate_(lambda x: x * 2, 3, 1) == 8
    """
    iter_ = iterate(func, value)
    for _ in range(times):
        next(iter_)
    return next(iter_)
Exemplo n.º 2
0
def iterate_(func, times, value):
    """Use toolz iterate function to actually iterate

    Args:
      func: function to iteratep
      times: the number of iterations
      value: start value

    Returns:
      the updated value
    """
    iter_ = iterate(func, value)
    for _ in range(times):
        next(iter_)
    return next(iter_)
Exemplo n.º 3
0
def iterate_times(func, times, value):
    """Iterate a function over a value.

    Args:
      func: the function to iterate
      times: the number of times to iterate
      value: the value to iterate over

    Returns:
      an update value

    >>> def inc(value):
    ...     return value + 1

    >>> iterate_times(inc, 0, 1)
    1

    >>> iterate_times(inc, 3, 1)
    4
    """
    iter_ = iterate(func, value)
    for _ in range(times):
        next(iter_)
    return next(iter_)
Exemplo n.º 4
0
def iterate_times(func, times, value):
    iter_ = iterate(func, value)
    for _ in range(times):
        next(iter_)
    return next(iter_)