Assuming Python 3.x and that the generator takes no arguments (the latter is trivial to add):
def wrapper(generator):
def _generator():
return map(my_formatting_func, generator())
return _generator
@wrapper
def my_gen():
For 2.x use itertools.imapinstead map.
source
share