Is there a continuation-like type for wrapping an execution block, like (Ctx => R) => R or (=> R) => R?
问题 I'm looking for such a type that would allow me to represent a context, in which a piece of code is run. For example: def withinContext[R]: ((=> R) => R) = (inner) => { initializeSomeResource() try { inner } finally { releaseTheResource() } } which then I can use simply as withinContext { ... } Or, if the inner block of code needs some information from the context, generalize it as def withinContext[R]: ((Ctx => R) => R) = ... Their use cases roughly correspond to Haskell's bracket_ and