applyfunc

class iteration_utilities.applyfunc(func, initial)

Successivly apply func on value.

Parameters:

func : callable

The function to apply. The value is given as first argument to the func, no other arguments will be passed during the function call.

initial : any type

The initial value for the function.

Returns:

results : generator

The result of the successivly applied func.

Examples

The first element is the initial value and the next elements are the result of func(value), then func(func(value)), ...:

>>> from iteration_utilities import applyfunc, getitem
>>> import math
>>> list(getitem(applyfunc(math.sqrt, 10), stop=4))
[3.1622776601683795, 1.7782794100389228, 1.333521432163324, 1.1547819846894583]

Warning

This will return an infinitly long generator so do not try to do something like list(applyfunc())!

current

(any type) The current value for the function (readonly).

New in version 0.6.

func

(callable) The function used (readonly).

New in version 0.6.