You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
The text was updated successfully, but these errors were encountered:
bbayles
added
the
pr-welcome
We are open to PRs that fix this issue - leave a note if you're working on it!
label
Feb 24, 2023
Description
starstarmap
is the lost cousin ofitertools.starmap
, so whereas the relation betweenmap
andstarmap
parallels the relation betweenfunction(a,b)
andfunction(*c)
, the relationship betweenmap
andstarstarmap
parallels the relation betweenfunction(a,b)
andfunction(**d)
.And similar to how
starmap
can be implemented as:starstarmap
could be implemented as:References
The argument for inclusion would be the fact that it simply seems missing from
itertools
, and its usefulness follows from the same pattern asstarmap
.Examples
A REST interface returns a list of JSON objects:
Each object needs to be processed and transformed via a processing function:
Now to convert from the JSON-parsed list of dictionaries to processed books, we can simply do:
The text was updated successfully, but these errors were encountered: