[release/9.0-staging] Fix LINQ handling of iterator.Take(...).Last(...) by stephentoub · Pull Request #112714 · dotnet/runtime

@stephentoub

When the Take amount is larger than the number of elements in the source `Iterator<T>`, Last ends up throwing an exception and LastOrDefault ends up returning the default value, rather than returning the last value in the taken region.

As part of fixing this, I sured up the tests to try to cover more such sequences of operations. In doing so, the tests got a lot slower, so I tracked down and fixed places where we were doing a lot of unnecessary work.

Copilot AI review requested due to automatic review settings

February 19, 2025 22:38

eiriktsarpalis