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

Enumerable.Single and Enumerable.SingleOrDefault overloaded implementations are inconsistent #14388

Closed
rverdier opened this issue Mar 26, 2015 · 5 comments
Assignees
Labels
area-System.Linq enhancement Product code improvement that does NOT require public API changes/additions
Milestone

Comments

@rverdier
Copy link

There is an inconsistency between the implementations of Enumerable.Single() and Enumerable.Single(predicate). Similarly there is another similar inconsistency between the implementations of Enumerable.SingleOrDefault() and Enumerable.SingleOrDefault(predicate)

The overloads which accept a predicate enumerate the whole sequence before eventually throwing, even if more than one matching elements were already found:

For consistency and performance reasons, it may be a good idea to make Enumerable.Single(predicate) and Enumerable.SingleOrDefault(predicate) methods able to fail fast and to throw an InvalidOperationException as soon as a second matching element is found.

If that seems like a reasonable change, I would gladly submit a pull request.

@MarcinJuraszek
Copy link
Contributor

There is a really old Connect report about that by Jon Skeet that was _Won't Fix_ed: https://connect.microsoft.com/VisualStudio/feedback/details/639955

@rverdier
Copy link
Author

Hello Marcin,

I found that Connect issue, as well as this one:

https://connect.microsoft.com/VisualStudio/feedback/details/810457

In the issue you mention, the reason why it was marked as "Won't fix" seems to be related to bug triage/schedule/priority. The answer even states (in 2011) that this issue will be re-opened for a future release. So I thought that in 2015, given the context – i.e. CoreFx being open-source, Microsoft accepting pull requests, etc. – it could be a good thing to fix this minor issue.

@ellismg
Copy link
Contributor

ellismg commented Mar 31, 2015

@AlekseyTs fixing this to early out seems reasonable, what do you think?

@AlekseyTs AlekseyTs assigned theoy and unassigned AlekseyTs Apr 1, 2015
@herecydev
Copy link

👍

@joshfree joshfree assigned VSadov and unassigned theoy Oct 13, 2015
@JonHanna
Copy link
Contributor

This is a subset of dotnet/corefx#2349, and as such was fixed by dotnet/corefx#2350.

@VSadov VSadov closed this as completed Jan 26, 2016
@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 1.0.0-rtm milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jan 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Linq enhancement Product code improvement that does NOT require public API changes/additions
Projects
None yet
Development

No branches or pull requests

9 participants