packed¶

class
iteration_utilities.
packed
(func, /)¶ Class that always returns
func(*x)
when called withpacked(func)(x)
.New in version 0.3.
Parameters: func : callable
The function that should be called when the packedinstance 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 tomap()
):>>> 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 tofilter()
):>>> 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 starfunction can be used but in case a function does not have such a convenience function already
packed
can be used.
func
¶ (callable) The function with packed arguments (readonly).
New in version 0.6.
