Async Generator Pipeline Compose (Python)
Compose async generators into a pipeline for lazy streaming with backpressure.
Code
import asyncio
async def pipe(source, *transforms):
current = source
for t in transforms:
current = t(current)
async for item in current:
yield item
def amap(fn):
async def inner(source):
async for item in source:
yield fn(item)
return inner
def afilter(pred):
async def inner(source):
async for item in source:
if pred(item):
yield item
return innerReport a problem with this exampleOpens a pre-filled issue on GitHub.