funcy
funcy copied to clipboard
Add unpack decorator
I propose to add a decorator which will unpack argument:
def process(foo, bar):
...
map(unpack(process), product(['foo1', 'foo2'], ['bar1', 'bar2']))
Is it a funcy way?
Look at itertools.starmap()
, it covers your use case.
Actually, no.
I have code like this pool.imap_unordered(unpack(process), iterable)
.
But you are right: in other cases, I can use starmap
. So this function is very specific and I don't know whether it is a good idea add it to funcy
.
If process()
is your function you can just unpack in a body, this narrows use cases. I agree that general usability is questionable. Other considerations (if we are going to add it) are name and keyword args support, which slows down the more common case.
So I let it hang for a while, let's see if anyone else wants it.
Yes, process()
is my own function, but I don't want to change it.
Other considerations (if we are going to add it) are name and keyword args support, which slows down the more common case.
So I let it hang for a while, let's see if anyone else wants it.
I agree
I just ran into a case where this could have been used. Unpacking the arguments in other ways is simple and readable enough that I don't think adding this is worthwhile.
As the mention above indicates, I ran into a case where this could be useful on a function composition pipeline if one of the fucntions returned a tuple with the arguments the next function needs, we could wrap the next function with the unpack()
decorator.