What Automatic Resource Management alternatives exist for Scala?

后端 未结 9 1377
半阙折子戏
半阙折子戏 2020-12-02 03:57

I have seen many examples of ARM (automatic resource management) on the web for Scala. It seems to be a rite-of-passage to write one, though most look pretty much like one a

9条回答
  •  时光取名叫无心
    2020-12-02 04:27

    I see a gradual 4 step evolution for doing ARM in Scala:

    1. No ARM: Dirt
    2. Only closures: Better, but multiple nested blocks
    3. Continuation Monad: Use For to flatten the nesting, but unnatural separation in 2 blocks
    4. Direct style continuations: Nirava, aha! This is also the most type-safe alternative: a resource outside withResource block will be type error.

提交回复
热议问题