repeatfunc

iteration_utilities.repeatfunc(func, *args, times=None)

Repeat calls to func with specified arguments.

Parameters:
funccallable

The function that will be called.

args

optional arguments for the func.

timesint, None, optional

The number of times the function is called. If None there will be no limit. Default is None.

Returns:
iterablegenerator

The result of the repeatedly called function.

Examples

>>> from iteration_utilities import repeatfunc, getitem
>>> import random
>>> random.seed(5)
>>> list(getitem(repeatfunc(random.random), stop=5))
[0.6229016948897019, 0.7417869892607294, 0.7951935655656966, 0.9424502837770503, 0.7398985747399307]
>>> random.seed(2)
>>> list(repeatfunc(random.random, times=3))
[0.9560342718892494, 0.9478274870593494, 0.05655136772680869]
>>> random.seed(None)

Warning

This will return an infinitely long generator if you don’t specify times.