Skip to content

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

Open
@iloveitaly

Description

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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions