Does Python support functional-style operations on asynchronous iterators? I know that I can use map, filter and itertools to lazily transform and consume data coming from normal generators:
from itertools import accumulate, takewhile
def generator():
a, b = 1, 1
while True:
yield a
a, b = b, a + b
# create another iterator, no computation is started yet:
another_iterator = takewhile(lambda x: x < 100, accumulate(generator()))
# start consuming data:
print(list(another_iterator))
# [1, 2, 4, 7, 12, 20, 33, 54, 88]
Now, the same thing is not supported on Python 3.6's asynchronous generators/iterators because of course they do not implement the normal iterator protocol:
async def agenerator():
a, b = 1, 1
while True:
yield a
a, b = b, a + b
accumulate(agenerator())
TypeError: 'async_generator' object is not iterable
Is there some kind of async map or async itertools to achieve the similarly lazy behaviour in Python 3.6/3.7?