-
Notifications
You must be signed in to change notification settings - Fork 311
Consider introducing starstarmap #679
Copy link
Copy link
Closed
Labels
pr-welcomeWe are open to PRs that fix this issue - leave a note if you're working on it!We are open to PRs that fix this issue - leave a note if you're working on it!
Description
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)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
pr-welcomeWe are open to PRs that fix this issue - leave a note if you're working on it!We are open to PRs that fix this issue - leave a note if you're working on it!