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

Map splat: treat each element as keyword arguments to be passed to the input function #148

Open
iloveitaly opened this issue Feb 1, 2024 · 1 comment

Comments

@iloveitaly
Copy link
Contributor

What I'd like to do is instead of writing something like:

id_list = [{'id': 1}, {'id': 2}, {'id': 3}]
results = lmap(
    lambda args: call_external_api(**(args | {"limit": 100})),
    id_list
)

I could instead create a partial on the method call and then just pass it to map:

id_list = [{'id': 1}, {'id': 2}, {'id': 3}]
results = lmap(partial(call_external_api, limit=100), id_list)

However, each element of the array is passed as a positional argument instead of splatted as keyword arguments. Any ideas of how to write map in a way that it splats the element and assumes it's a dictionary that should be converted into keyword arguments?

Should this be an additional map variant added to the library? Happy to write up a PR for it.

@Suor
Copy link
Owner

Suor commented Feb 1, 2024

Won't list comprehensions solve this nicely?

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

No branches or pull requests

2 participants