Instead of writing, def fn() = { val result = someExpression doSomethingElse() result } I've found myself writing code like, def fn() = try someExpression finally doSomethingElse() more, even when `someExpression` is pure. I'm not entirely sure how I feel about it.
I'd say it's a bit unintuitive, yes, based on the typical meaning of try/finally, but that's what made it interesting! Though is the use case actually so different from resource handling, if the key point is that a side-effect should always happen right after some code returns?
-
-
Yes, I guess side effects and resource handling can be seen as equivalent. I think struggle, however, with the example. Couldn't you just write def fn() = { doSomethingElse() someExpression } Or is someExpression used by the side effect in the try-finally?
-
I actually meant to say "didn't throw exceptions" rather than "pure" in the original tweet... trying too hard to save characters in my tweet. So the order is significant.
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.