4 ms·
It still has exceptions- but exceptions are normal. Errors are normal. How would one do : https://fsharpforfunandprofit.com/rop/ https://fsharpforfunandprofit.c
by InDubioProRubio 2y ago
It still has exceptions- but exceptions are normal. Errors are normal.
How would one do : https://fsharpforfunandprofit.com/rop/ https://fsharpforfunandprofit.com/rop/ in python?
- benrutter 2y agoI think monad patterns can work pretty well in python, but my experience is nobody uses them. I wrote a small utility library for exactly that kind of "railway oriented programming" if you're curious about what it'd look like in python: https://github.com/benrutter/ufo-tools https://github.com/benrutter/ufo-tools
- meehai 2y agowhat about this pattern? https://www.inngest.com/blog/python-errors-as-values https://www.inngest.com/blog/python-errors-as-values I tried it once in an sqlite DB connector with some business logic and simply checking stuff like res: DBException | Result = db_handler.some_business_logic() if isinstance(res, DBException): return res # you can also log or even raise if this function isn't returning exceptions as values # guaranteed to be Result type here See here: - https://gitlab.com/meehai/drpciv-flask/-/blob/main/be/db_handler.py?ref_type=heads#L186 https://gitlab.com/meehai/drpciv-flask/-/blob/main/be/db_han... - https://gitlab.com/meehai/drpciv-flask/-/blob/main/be/app.py?ref_type=heads#L69 https://gitlab.com/meehai/drpciv-flask/-/blob/main/be/app.py...