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

Implement uncurry #598

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Implement uncurry #598

wants to merge 1 commit into from

Conversation

dimitriye98
Copy link

An implementation of a utility function I find myself needing to implement in almost every codebase I use toolz in. uncurry takes a function of multiple arguments and returns a function which takes a single tuple or dict and calls the wrapped function with the argument unpacked. Based on the Haskell function of the same name. This is particularly useful for function pipelines with lambdas, as Python 3 removed the implicit destructuring of lambda arguments present in Python 2.

I considered also the use of star as the name, to match itertools.starmap, however as this also supports dictionaries I decided a new name made sense. Alternatively, we could be explicit on whether a dict or a tuple is being passed, e.g.

@curry
def star(func, args):
    return func(*args)

@curry
def sstar(func, kwargs):
    return func(**kwargs)

My preference is letting the dispatching be automatic, but I can see the argument both ways.

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

Successfully merging this pull request may close these issues.

1 participant