After reading about Functional Programming, I've come to realize that I often enter this situation.
-->Iterate something in Y based on A
--->Do Z to X
Now, When I want to implement FindXinYAndDoWTo(A)
Then, I suddenly realize that my code above mixes the action of finding something and what to do with it once I have found it.
I should have passed Z as an Action<X> instead.
If I have this c# code:
private void FindAndDeletePersonByName(data d, string name ) // Yeah, I know linq. This is for example.
foreach(person p in data.persons)
As Time progresses, there are two things I may want to change while reusing the rest: Either the comparison predicate or the action of deleting.
If I select the p.Name==name and choose "Introduce variable", I am given a bool type because that is the return type of the selected expression.
But what I really want to do, is to get a Func<Bool> expressed as a lambda expression:
Func<bool> predicate = ()=>p.Name==name;
and I wish to extract "name" turning the declaration into
Func<string,bool> predicate = (theName)=> p.Name==theName;
...so that I will be able to either extract the whole Func as a parameter, implement it as a strategy pattern or hardcode it differently in subclasses.
A prime objective of object orientation is to separate what changes from what stays the same. By making lambdas a first class citizen, I think resharper could do wonders.