The memento pattern is great for transaction-like processing. Having a handy implementation around might not be the worst thing.
Python, 81 lines
Closures offer truly charming solution opportunities. In this example, the Memento function returns a closure that keeps the originator as well as the captured state in its scope, and restores the originator's state when called. Now, according to the memento pattern, the object representing the originator's state should be opaque, so the only thing you should be able to do with it is return it to the originator for state restoration. Well, I think the presented closure is as close (rem: note that subtle wording ;) to this definition as it can be.
Okay, we knew this was going to be easy with python. (After all, it seems to be the perfect design pattern implementation language, as you can almost always find a way to implement a pattern in a generic and reusable way.) And, once we've got it, we can build on top of it all sorts of useful (or at least nice-sounding ;) things:
Cheers and happy transacting!
[See Also] Memento pattern description at http://en.wikipedia.org/wiki/Memento_pattern