Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select and Count #8

Open
jackmott opened this issue Feb 4, 2019 · 1 comment
Open

Select and Count #8

jackmott opened this issue Feb 4, 2019 · 1 comment

Comments

@jackmott
Copy link

jackmott commented Feb 4, 2019

I was reading an article about .NET Core, where early versions had a bug/feature where if you had something like collection.Select(foo).Count(); it wouldn't actually perform the Select operation, since it doesn't matter, you only need the count. But, since this would prevent side effects from happening, it was a breaking change and they had to fix it.

But, this seems like an optimization that LinqAF could keep. Maybe you already do, but if not just wanted to get the idea out there.

@manofstick
Copy link

The did leave remnants of this optimization in there (which, you could argue, are breaking changes...):

var count = 0;
var ignore =
    Enumerable
    .Range(0, 100)
    .Select(x => { ++count; return x; })
    .Skip(90)
    .ToList();
switch (count)
{
    case 10: System.Console.WriteLine(".net core (probably...)"); break;
    case 100: System.Console.WriteLine(".net framework (probably...)"); break;
    default: System.Console.WriteLine("who knows?"); break;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants