python-trio / outcome

Capture the outcome of Python function calls

Home Page:https://outcome.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Monadic behavior

bluetech opened this issue · comments

Does it make sense to have an Outcome[Outcome[T]]? In some languages/libraries, for example JavaScript Promise, this is not possible; instead this is always flattened to Outcome[T].

I don't think such magic is necessary in this library, but thought I'd bring it up.

All the places we use it in trio we don't want this kind of collapsing. We want to take an arbitrary function, wrap its outcome in an object, move that object somewhere else, and then unwrap it again, and have this whole process be perfectly transparent. Collapsing nested Outcomes would break this transparency, since "arbitrary function" includes those that return Outcome objects.

Example: trio.run_sync_in_worker_thread (capture, some_func) should return an Outcome, but wouldn't if we did collapsing.

I guess if someone has a compelling use case we could add an explicit collapse method or something? I guess I'll close to until someone comes up with that use case though :-)