|
|
|
|
|
by wonderzombie
5070 days ago
|
|
I'm guessing you can't really do a 1:1, although maybe the OP can clarify. They do stuff like this in jQuery, so I can't imagine it's all that difficult in Python. My initial thought would be to write something analogous to Maybe. You can't pattern match in Python, which is a shame, but you could make it so that foo.bar().baz().quux() will return MaybeResult, which everything involved in the transaction inherits from. MaybeResult might have a "success" variable on it indicating whether it ought to be treated as Nothing. Otherwise, check "result." This is naive but it gets you a little bit closer to fault-tolerant chaining of interdependent methods. Not as nice as Haskell, obvs. :) |
|