Skip to content

Add unpack decorator - #62

Closed
ADR-007 wants to merge 2 commits into
Suor:masterfrom
ADR-007:feature/add-unpack-decorator
Closed

ADR-007 wants to merge 2 commits into
Suor:masterfrom
ADR-007:feature/add-unpack-decorator

Conversation

@ADR-007

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

Copy link
Copy Markdown

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

Suor commented Feb 11, 2018

Copy link
Copy Markdown
Owner

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

@ADR-007

ADR-007 commented Feb 11, 2018 •

Copy link
Copy Markdown
Author

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

Suor commented Feb 11, 2018

Copy link
Copy Markdown
Owner

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

ADR-007 commented Feb 11, 2018

Copy link
Copy Markdown
Author

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

taleinat commented May 11, 2018 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown

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.

@Suor Suor closed this Sep 19, 2025
@Suor

Suor commented Sep 19, 2025

Copy link
Copy Markdown
Owner

In the vast majority of cases Python builtin syntax is superior

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