Replies: 1 comment
-
A local mutable variable wouldn't be bad for something like this, and I would expect it to compile close or basically to what you would expect in a C language. You could factor out the closure into a top level function which tends to work better than closures when dealing with problems with local variables and effect inference. I think it is good practice to avoid the shadowing. Good names can make it clear when something is an intermediate result, an accumulator, or actually a finished product. As such here is one way you could refactor the code.
Or you could do something a bit more drastic and factor out the transforming logic into your own custom
|
Beta Was this translation helpful? Give feedback.
-
I've been working on some code where using a mutable variable leads to it potentially escaping the function due to effect polymorphism, and thus I've resorted to shadowing the variable declarations instead.
This, however, leads to a compiler warning of shadowed variables, which led me to the question in the title.
Should I attempt to make the variable mutable, or just ignore the compiler warnings?
For context, this is the code I'm talking about, and the shadowed variable here is
out
:Beta Was this translation helpful? Give feedback.
All reactions