I have this code, which is supposed to return a value type, applying at each step the transformations specified in steps
.
private static T Transformed<T>(T x, params Func<T, T>[] steps) where T : struct
{
if ((steps?.Length ?? 0) == 0)
{
return x;
}
var reallyEmpty = steps.Where(f => (x = f(x)).Equals(int.MinValue));
return x;
}
I only need the Where
extension to get through each step without using a loop, thus I use a condition which could probably never be true (Equals(int.MinValue)
).
But if I have this calling code, I get 5
and not 15
, how I'd expect.
int res1 = Transformed(5, x => x * 2, x => x + 5);
Console.WriteLine(res1);
My question is why? Doesn't Where
go through each element and check it?