Snippets tagged dispose

  • Deferred clean-up code (Go/Swift-style)

    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 people like this

    Posted: 1 years ago by Anton Tcholakov