sideeffects

class iteration_utilities.sideeffects(iterable, func, times=0)

Does a normal iteration over iterable and only uses func each times items for it’s side effects.

Parameters
iterableiterable

Iterable containing the elements.

funccallable

Function that is called for the side effects.

timesint, optional

Call the function each times items with the last times items. If 0 the argument for func will be the item itself. For any number greater than zero the argument will be a tuple. Default is 0.

Returns
iteratorgenerator

A normal iterator over iterable.

Examples

A simple example:

>>> from iteration_utilities import sideeffects
>>> list(sideeffects([1,2,3,4], print))
1
2
3
4
[1, 2, 3, 4]
>>> list(sideeffects([1,2,3,4,5], print, 2))
(1, 2)
(3, 4)
(5,)
[1, 2, 3, 4, 5]
__length_hint__()

Tries to estimate for the length of the instance (returns 0 if an estimation is not possible).

count

(int) The current count for the next func call (readonly).

New in version 0.6.

func

(callable) The function that is called by sideeffects (readonly).

New in version 0.6.

times

(int) A counter indicating after how many items the func is called (readonly).

New in version 0.6.