Given a lambda with a captured local variable,
- Add a new parameter to the lambda
- Inside the lambda, replace uses of the local with uses of the new parameter
- Where the lambda is called, pass in the local.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given: | |
Y y = ... | |
Action action = () => { | |
var x = F(y); | |
G(x); | |
}; | |
action(); | |
// After: | |
Y y = ... | |
Action action = (_y) => { | |
var x = F(_y); | |
G(x); | |
}; | |
action(y); |
I believe this is a refactoring: I believe that this transformation has no effect on the behavior of the code. But I'm not completely certain.
This operation is not allowed if the value of the local is changed inside the lambda.
This is almost the same operation as Introduce Parameter.