Skip to content

Consider introducing starstarmap #679

@Skeen

Description

@Skeen

Description

starstarmap is the lost cousin of itertools.starmap, so whereas the relation between map and starmap parallels the relation between function(a,b) and function(*c), the relationship between map and starstarmap parallels the relation between function(a,b) and function(**d).

And similar to how starmap can be implemented as:

def starmap(function, iterable):
    for args in iterable:
        yield function(*args)

starstarmap could be implemented as:

def starstarmap(function, iterable):
    for args in iterable:
        yield function(**args)

References

The argument for inclusion would be the fact that it simply seems missing from itertools, and its usefulness follows from the same pattern as starmap.

Examples

A REST interface returns a list of JSON objects:

[
    {"identifier": 1, "title": "The Cathedral and the Bazaar"},
    {"identifier": 2, "title": "Homesteading the Noosphere"},
   ...
]

Each object needs to be processed and transformed via a processing function:

def func(identifier, title):
    ...
    return Book(...)

Now to convert from the JSON-parsed list of dictionaries to processed books, we can simply do:

books = starstarmap(func, dictionaries)

Metadata

Metadata

Assignees

No one assigned

    Labels

    pr-welcomeWe are open to PRs that fix this issue - leave a note if you're working on it!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions