Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unpack decorator #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ADR-007
Copy link

@ADR-007 ADR-007 commented Feb 10, 2018

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?

@Suor
Copy link
Owner

Suor commented Feb 11, 2018

Look at itertools.starmap(), it covers your use case.

@ADR-007
Copy link
Author

ADR-007 commented Feb 11, 2018

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.

@Suor
Copy link
Owner

Suor commented Feb 11, 2018

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.

@Suor Suor mentioned this pull request Feb 11, 2018
@ADR-007
Copy link
Author

ADR-007 commented Feb 11, 2018

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

@taleinat
Copy link
Contributor

taleinat commented May 11, 2018

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.

@cardoso-neto
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants