2 people like it.
Like the snippet!
Go and Swift have a dedicated defer keyword which allows the programmer to specify code which should run when leaving the current scope, irrespective of errors. F# supports a similar pattern with IDisposable and the use keyword, but this requires either defining a class definition or object expression and the extra syntax can make the code less expressive. This snippet defines a simple helper function called "defer" to remedy the situation.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: |
|
Link: | http://fssnip.net/rl |
Posted: | 9 years ago |
Author: | Anton Tcholakov |
Tags: | dispose , defer , try/finally , exceptions |