I am looking for a Python decorator that can make a function recursive. I find that I am writing a lot of such functions:
def xyz(data): if not isinstance(data, TypeThatDenotesSingularity): return map(xyz, data) return singular_xyz(data)
I suppose there should be a decorator somewhere (in the standard library?) That can reduce the tad notation:
@recursive(TypeThatDenotesSingularity) def xyz(data): return singular_xyz(data)
I searched, but it seems I canβt find anything. Perhaps I am missing some essential terminology?
Thanks for pointing me in the right direction!
python decorator recursion
Tim molendijk
source share