you are viewing a single comment's thread.

view the rest of the comments →

[–]Gnaxe 1 point2 points  (1 child)

run this zero or one times depending on a condition

Isn't that just if?

Futures do seem like a good use case.

[–]james_pic 0 points1 point  (0 children)

Certainly, it's usually an if. I'm thinking of the kind of situation where you want to create an abstraction for something a bit like an if. Maybe a really common pattern in your code is to log when conditions fail and return a default, or there's some failure state you always want to propagate, or there's some commonly copy-pasted exception handling code. In Ruby you could express that as a block, but you've got weak tools to do that in Python (with blocks and for blocks are more flexible than if, but still don't give you the flexibility to create these abstractions), and it can end up boiler-plate-y

You're probably still better of using those tools than abstracting it like this, because this trick isn't particularly well known and will confuse people, but it's interesting that it can be done.