A number of people have asked me why
there is no Microsoft-provided
“ForEach” sequence operator extension
method. The List class has such a
method already of course,but there’s
no reason why such a method could not
be created as an extension method for
all sequences.
…
But we can go a bit deeper here. I am
philosophically opposed to providing
such a method,for two reasons.
…
The first reason is that doing so
violates the functional programming
principles that all the other sequence
operators are based upon. Clearly the
sole purpose of a call to this method
is to cause side effects.
…
The second reason is that doing so
adds zero new representational power
to the language.
…
Well,the VS Languages team does not have any influence on what goes into List. I personally find the “ForEach” method on List philosophically troubling for all the same reasons that I would find an extension method on IEnumerable troubling. (And the VSL team does control that.) The one mitigating factor is that List is clearly designed to be a mutable,not-side-effect-free data structure,so using expressions that mutate it seems slightly less bad. — Eric