suned / pfun

Functional, composable, asynchronous, type-safe Python.
https://pfun.dev/
MIT License
151 stars 14 forks source link

Effect.map can't handle generators #112

Closed suned closed 2 years ago

suned commented 2 years ago

map currently uses asyncio.iscoroutine to determine if the result of a continuation function must be awaited. When a continuation returns a generator `asyncio.iscoroutine mistakes this generator for a coroutine:

from pfun import success

def f(_):
    yield from [1, 2, 3]

success(0).map(f).run(None)  # TypeError: object generator can't be used in 'await' expression