packed

class iteration_utilities.packed(func, /)

Class that always returns func(*x) when called with packed(func)(x).

New in version 0.3.

Parameters:
funccallable

The function that should be called when the packed-instance is called.

Examples

Creating packed instances:

>>> from iteration_utilities import packed
>>> from operator import eq
>>> five = packed(eq)
>>> five((2, 2))
True

This is a convenience class that emulates the behaviour of itertools.starmap() (compared to map()):

>>> from itertools import starmap
>>> list(map(packed(eq), [(2, 2), (3, 3), (2, 3)]))
[True, True, False]
>>> list(starmap(eq, [(2, 2), (3, 3), (2, 3)]))
[True, True, False]

and starfilter() (compared to filter()):

>>> from iteration_utilities import starfilter
>>> list(filter(packed(eq), [(2, 2), (3, 3), (2, 3)]))
[(2, 2), (3, 3)]
>>> list(starfilter(eq, [(2, 2), (3, 3), (2, 3)]))
[(2, 2), (3, 3)]

Of course in these cases the appropriate star-function can be used but in case a function does not have such a convenience function already packed can be used.

__call__(x, **kwargs)

Returns func(*x, **kwargs) using func.

func

(callable) The function with packed arguments (readonly).

New in version 0.6.