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

Add HasAtLeast<TSource>(this IEnumerable<TSource>, int) #19505

Closed
shmuelie opened this issue Nov 29, 2016 · 4 comments
Closed

Add HasAtLeast<TSource>(this IEnumerable<TSource>, int) #19505

shmuelie opened this issue Nov 29, 2016 · 4 comments
Labels
api-needs-work API needs work before it is approved, it is NOT ready for implementation area-System.Linq
Milestone

Comments

@shmuelie
Copy link
Contributor

Motivation

When working with sequences of just IEnumerable<T> calling Count() can be very expensive if Count() is forced to enumerate through the whole sequence. When checking if a sequence has X elements or more calling Count() is not just expensive but wasteful.

Proposal

namespace System.Linq
{
    public static class Enumerable
    {
+       /// <summary>
+       ///     Returns if a sequence has at least a certain amount of elements.
+       /// </summary>
+       /// <typeparam name="TSource">The type of elements of <paramref name="source"/>.</typeparam>
+       /// <param name="source">An <see cref="IEnumerable{T}"/> to check the length of.</param>
+       /// <param name="atLeast">The minimum amount of items that <paramref name="source"/> should have.</param>
+       /// <returns><see langword="true"/> if <paramref name="source"/> has at least <paramref name="atLeast"/> elements. <see langword="false"/> otherwise.</returns>
+       /// <exception cref="ArgumentNullException"><paramref name="source"/> is <see langword="null"/>.</exception>
+       /// <exception cref="ArgumentOutOfRangeException"><paramref name="atLeast"/> must be zero or greater.</exception>
+       public static bool HasAtLeast<TSource>(this IEnumerable<TSource> source, int atLeast);
    }
}
@karelz
Copy link
Member

karelz commented Nov 29, 2016

It can be rewritten as Skip(atLeast).Any().
Personally I don't think it is worth a new API method - we do not want to bloat the list to unusable thing.
If it is popular API/wrapper, then I might be ok with it, but I don't think it is ...

@shmuelie
Copy link
Contributor Author

I admittedly had not thought of that! I'll leave it open in case anyone else comes up with reasons to keep it.

@karelz
Copy link
Member

karelz commented Nov 29, 2016

I would suggest to close it. If someone has evidence this is indeed useful, just comment here and we can reopen it.

@karelz karelz closed this as completed Nov 29, 2016
@stephentoub
Copy link
Member

It can be rewritten as Skip(atLeast).Any(). Personally I don't think it is worth a new API method - we do not want to bloat the list to unusable thing. If it is popular API/wrapper, then I might be ok with it, but I don't think it is

I agree it's not worth adding another API, though it may make https://github.com/dotnet/corefx/issues/2327#issuecomment-263578679 more impactful to do.

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 2.0.0 milestone Jan 31, 2020
monojenkins pushed a commit to monojenkins/runtime that referenced this issue Apr 16, 2020
… (dotnet#19505)

* [wasm][debugger] Show signature for delegate, or target, if available

- As object properties, we return a `Target` which has the signature of
the delegate target.

Fixes mono/mono#19382

* [wasm][debugger] Some tidying up

* [wasm][debugger] Remove unused `sig_desc`

* [wasm][debugger] Simplify code, avoid extra allocations

.. as suggested by @lewing

(cherry picked from commit 4eca12e794764da1a0646e77af5b8c60a2e2767a)
@ghost ghost locked as resolved and limited conversation to collaborators Dec 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-needs-work API needs work before it is approved, it is NOT ready for implementation area-System.Linq
Projects
None yet
Development

No branches or pull requests

4 participants