suned / pfun

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

Infer send type of yield assignments of ask() in with effect decorated reader functions #24

Closed suned closed 4 years ago

suned commented 5 years ago

This could also be used in an eventual effect rotation "god monad" ala ZIO


from pfun.reader import Reader, ask, with_effect
from typing import TypeVar, Generator, Any

A = TypeVar('A')
R = TypeVar('R')
Readers = Generator[Reader[R, Any], Any, A]

@with_effect
def f() -> Readers[str, int]:
    env = yield ask()
    reveal_type(env)  # should be str