[TestMethod]
public void FunctionExtention_CombinePredicates_Should_Avoid_Closure()
{
var value = 0;
var predicates = new Predicate<int>[]
{
x => x > value
};
var result = FunctionExtentions.CombinePredicates(predicates);
value = 1000;
Assert.IsTrue(result(2));
}
but this test don't pass, I think I must create local copy using deep copy, but C# don't have standard thing.
public static Predicate<T> CombinePredicates<T>(Predicate<T>[] predicates)
{
return item => predicates.All(predicate => predicate(item));
}