-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reader monad usage #37
Comments
I often find that eliminating "plumbing" parameters with from pfun.reader import map_m, Reader, ask
def main():
connection = Connection(URI='testuri')
result = process_all().run(connection)
print(result)
def process_all() -> Reader[Connection, str]:
return map_m(process, range(5)).map(lambda _: 'result')
def process(item: int) -> Reader[Connection, None]:
return ask().map(lambda c: print(item, c))
|
I apologize that I don't talk about |
Maye from pfun.reader import sequence, Reader, ask
def process_all() -> Reader[Connection, str]:
return sequence(process(i) for i in range(5)).map(lambda _: 'result') |
Thanks, so if I want to do some stuff with a result coming from
|
Another question :), if I want to use the Writer Monad together with Reader Monad:
there is a better way to do it? It seems a little ugly to me, and it's a very simple example. |
Exactly!
This is normally referred to as effect composition, and no, its not very nice. In other frameworks you'll find special constructs for dealing with this (monad transformers e.g). For pfun I'm working on another approach which will be released beginning of 2020 |
I'm totally new of functional programming, I'm trying to use a reader monad to get rid of passing a lot of function parameter in my code, but I don't understand how to use it properly. Here a very simple use case.
how can I get
Connection
in theprocess
function without explicitly passing it? If I must pass it then I don't understand the advantage to directly passConnection
through functions without using a reader monad. What I'm missing?Thanks.
The text was updated successfully, but these errors were encountered: