I've got the following generator, it's a bit like itertools.accumulate, except that it takes the next input from the function's own output rather from than an iterable:
def turboaccumulate(f, initial):
x = initial
while True:
x = f(x)
yield x
Is anything like this contained in the standard library, or does the Python documentation contain a recommended recipe for this? I was unable to find one in about 20 minutes of searching.
Or, at the very least: what is this operation called? (I highly doubt "turbo-accumulate" is the recognized name for it.)
The context of this was an effort to parse the inscrutable lisp behemoth here into something understandable by mortals, which I got down to:
def blum_blum_shub(p, q, s):
#assert coprime(p, q)
M = p * q
return turboaccumulate(lambda x: pow(x, 2, M), s)
However, that final function call just looks absolutely goofy, so I'm wondering if it's present in the standard library or at least has a more recognized name.