Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

2
  • 4
    I don't think this handles conditional evaluation, or does it? With side-effect free branches this doesn't matter (like in your example), but if it's something with side-effects you'll run into problems. Commented Sep 26, 2019 at 12:34
  • Yes, actually from what Ashton said, it does indeed not offer the conditional evaluation. So in other cases, one could just write test = function1(); if condition {test = function2()}, which would be the same and would require no type assertion (faster). In the case of the answer where there is a return involved, no idea. Also depends on if both evaluations or at least the 2nd is very expensive or not. Still thank you for the answer! Seems a good idea despite this. Commented Nov 3, 2021 at 23:30